Using Win32 socket handles?

Is there any way to do a socket "Select()" on Win32 socket handles in C#, other than using a PInoke style call on the C socket "Selelct()" function?
I'm writting C# code that has to use a third party C dll. Thanks to the people at (www.swig.org) I've wrapped up the dll functions and can call them from C#.
The dll makes a number of TCP/IP socket connections to a server. It has a function that allows me to poll to see if any messages have arrived and I've being using this succesfully via a timed polling loop.
It is possible to get the win32 socket handles from the dll, the idea originally being that they get used in a C style "select()" call, in this way the applciation can be event rather than poll driven.
I'd like to make my C# app a bit more event driven but don't know the best way to proceed. Note: I only want to be notified when something arrives at the sockets I'll still use the dll code to retreive messages.
Ta,
Paul
[977 byte] By [TaffyDownUnder] at [2008-2-7]
# 1
Using Win32 calls I attached and event to the FD returned by the Win32 function.
[DllImport("Ws2_32.dll")]
private static extern int WSAEventSelect( IntPtr socketFD, IntPtr socketEventHandle, Int32 lNetworkEvents);

[DllImport("Kernel32.dll")]
private static extern IntPtr CreateEvent( IntPtr attributes, long manualReset, long initialState, String Name);
....
IntPtr Handle = CreateEvent( IntPtr.Zero, 0, 0, null) ;
WSAEventSelect( new IntPtr( FD), Handle, 0); // 0 for FD_READ

This code is used in a new C# class I created which derives from WaitHandle, and I set the Handle in this class to the handle I created in the CreateEvent() above. If I pass these handles into a call to WaitHandle.WaitAny() none of the events signal. If in the CreateEvent() I initially set the bInitialState to 1, I get the initial signal but then no more afterwards.
So it seems that the event created is OK but it is not getting set by the socket when receiving data.
Are there any special settings that need to be done on the socket, in the C code, to get the event stuff to work (I'd rather not have to change it since it's supplied by a third party, but I do have the source).
Ta,
Paul


TaffyDownUnder at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 2
Found it, I miss read the winsock2.h file the FD_READ flag is of course 1 not 0, duh. All works fine now.
Paul
TaffyDownUnder at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...

.NET Development

Site Classified