I apologize in advance if I am posting to the wrong group, but at least
one of my questions is related to Platform Invoke in C#.
I am using .NET Framework 1.1, and for improved performance, I need to
be able to reuse a client socket by placing it into a pool.
Unfortunately, with .NET Framework 1.1 I have no way to close a
socket's connection to a remote host without disposing of the socket's
resources altogether (i.e, Socket.Close()), which prevents reuse of the
socket.
It appears that the .NET Framework 2.0 provides a Disconnect() method
that allows the socket handle to be reused, but I am restricted to
using .NET Framework 1.1 at this time.
My strategy right now is to extend the System.Net.Sockets.Socket class
to include a Disconnect() method that calls the Winsock2 API's
DisconnectEx() function, but there are two problems that I am unable to
overcome:
1. I cannot get the .NET Framework to locate an entry point for the
DisconnectEx() function. The following code returns an exception that
states that an entry point cannot be found for the DisconnectEx()
function:
[DllImport("ws2_32.dll")]
private static extern Boolean DisconnectEx(IntPtr hSocket,IntPtr
lpOverlapped,UInt32 dwFlags, UInt32 reserved);
When I try to call this declared function, the exception is thrown. Am
I referencing the correct dll?
2. I am uncertain as to whether or not I will have to wrap the Winsock2
API's ConnectEx() function in order to reuse the handle. The API
documentation states that the handle can be passed to the ConnectEx()
and AcceptEx() functions when the DisconnectEx() function is called
with the dwFlags argument set to TF_REUSE_SOCKET. Which, to me,
implies that I may also have to wrap the TransmitFile() API function in
my class.
It seems silly to me that I might have to essentially rewrite the
System.Net.Sockets.Socket class in order to get a disconnect method
that allows me to reuse my socket. I simply want the same functionality
as that provided by the .NET Framework 2.0's Socket.Disconnect()
method.
Can anyone make a suggestion that might get me on my way?
Thanks,
Greg