[Mono-dev] Control-C handler

Jonathan Pryor jonpryor at vt.edu
Mon Jan 28 12:29:02 EST 2008


On Mon, 2008-01-28 at 15:25 +0100, Paolo Molaro wrote:
> Well, those methods shouldn't be in that namespace and the names
> are not really nice.
> Ignore maps well to a static Ignore (int signal) method but
> I can't come up with a nice name for the other two cases.
> An alternative is:
> 	enum SignalAction {
> 		Default,
> 		Ignore,
> 		Error
> 	}
> 
> and
> 	static int SetSignalAction (int signum, SignalAction action);

Done; added to Stdlib.

> > Index: Mono.Unix/UnixSignal.cs
> > ===================================================================
> > --- Mono.Unix/UnixSignal.cs	(revision 0)
> > +++ Mono.Unix/UnixSignal.cs	(revision 0)
> > +namespace Mono.Unix {
> > +	public class UnixSignal : WaitHandle {
> 
> It should have a finalizer.

It inherits a finalizer from WaitHandle.

> > +		public unsafe int Count {
> > +			get {return Info->count;}
> > +			set {Info->count = value;}
> 
> Crashes when Info is NULL.

Fixed; the Info property now asserts before returning.

> > +		#region WaitHandle overrides
> > +		protected unsafe override void Dispose (bool disposing)
> > +		{
> > +			if (signal_info == IntPtr.Zero)
> > +				return;
> > +			uninstall (_signum);
> > +			signal_info = IntPtr.Zero;
> > +		}
> 
> This doesn't implement the documented Dispose pattern.

It does.  Since only an unmanaged resource is wrapped, `disposing' is
ignored as this cleanup always needs to be done.

> > Index: signal.c
> > ===================================================================
> > --- signal.c	(revision 92060)
> > +++ signal.c	(working copy)
> > +#include <poll.h>
> 
> As reported already the last time, you can't unconditionally use poll.

I now use select.

> It is important (as in my initialy API sketch) that this function take
> the signal_info and not the dignal number, as this implementation allows
> only just an handler per signal in the API.

This has been corrected.  We now support up to 64 signal handlers within
a process, and the same signal can be registered multiple times; each
such registration gets a different index, and is thus independent.

The only other major change is the addition of a
UnixSignal.WaitAny(UnixSignal[]) method, which allows waiting on more
than one handle (since WaitHandle.WaitAny() can't currently be used with
WaitHandle subclasses like UnixSignal).

There are two remaining questions:

1. Should WaitHandle actually be the base class?  Dick tells me that we
could add the support for UnixSignal to be a "proper" WaitHandle so that
WaitHandle.WaitAny() would work as expected, but this would be post-2.0.
I'd prefer to keep WaitHandle as the base type so that it doesn't need
to be changed in the future.

2. Should the Wait*() be exposed?  I think they're quite useful, though
they'd be more useful if they could be used with WaitHandle.WaitAny()...

Changes attached.

OK to commit?

 - Jon

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Mono.Posix-v4.diff
Type: text/x-patch
Size: 8440 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080128/b41d82ff/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: support-v4.diff
Type: text/x-patch
Size: 6058 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080128/b41d82ff/attachment-0001.bin 


More information about the Mono-devel-list mailing list