[Mono-dev] Non-TCP/IP socket access

Andy Hume andyhume32 at yahoo.co.uk
Fri Jul 22 11:12:14 EDT 2011


> -----Original Message-----
> From: mono-devel-list-bounces at lists.ximian.com 
> [mailto:mono-devel-list-bounces at lists.ximian.com] On Behalf 
> Of Robert Jordan
> Sent: 22 July 2011 15:15
> To: mono-devel-list at lists.ximian.com
> Subject: Re: [Mono-dev] Non-TCP/IP socket access
> 
> On 22.07.2011 15:40, Robert Jordan wrote:
> > On 22.07.2011 15:00, Andy Hume wrote:
> >>> From: mono-devel-list-bounces at lists.ximian.com
> >>> [mailto:mono-devel-list-bounces at lists.ximian.com] On Behalf Of 
> >>> Robert Jordan
> >>> Sent: 22 July 2011 12:43
> >>> To: mono-devel-list at lists.ximian.com
> >>> Subject: Re: [Mono-dev] Non-TCP/IP socket access
> >>>
> >>> On 22.07.2011 13:08, Andy Hume wrote:
> >>>> Presumably I can't convert my fd to a wapi handle 
[...]
> But there is another way:
> 
> 1) create an INET socket with Mono's System.Net.Sockets.Socket class
> 
> 2) get its FD via reflection
> 
> 3) close it via p/invoke with close(2) (see "man 2 close")
> 
> 4) create your socket via p/invoke with socket(2)
> 
> 5) don't close the socket create in (4) yourself, because 
> WAPI will take care of it.
> 
> 6) use the socket created in (1) throughout your application
> 
> Because Unix is reusing descriptors, the socket created in 
> (4) will have the same number, and WAPI will be happy.
> 
> Put this code inside a lock to prevent that some other thread 
> is stealing your fd.
> 
Wow.  I'll give that a go.  What kind of lock?  Just Monitor.Enter?

Ohh wait.  The handle in the Socket is (surely?) the WAPI Handle and not
the FD...

Andy



More information about the Mono-devel-list mailing list