[Mono-list] Use existing socket descriptor
mono at rickparrish.ca
Mon Mar 30 19:20:19 UTC 2015
In August of 2013 I asked about using an existing socket handle. Here's the
original message as a reference:
I ended up abandoning that project so lost interest, but the need has come
up again. So I looked into it further this time, and have made a bit of
progress. What I'm doing is:
- Populate a SocketInformation object with data, including the socket handle
passed from the server program.
- Create a new Socket by passing in the SocketInformation object.
- I modified the above constructor to call OpenSocket_Internal (a new
internal function I added)
- OpenSocket_Internal calls _wapi_open_socket (another new function I added)
- _wapi_open_socket calls _wapi_handle_new_fd (I saw _wapi_accept and
_wapi_socket both call this, so figured it was what I needed)
With these changes I'm now able to have the server pass the numeric socket
handle to my mono program, which can then create a managed Socket class to
make use of that handle. And everything works fine, until my program
When it terminates the connection is being closed, so the server thinks I've
disconnected and also terminates. What I would like to happen is for the
connection to remain open so then the server will be able to resume socket
I/O with the client.
On Windows I had this problem as well, and I found that if I called
Socket.Close() without first calling Socket.Shutdown() then the connection
remained open, but no such luck here. I've tried commenting out various
bits of the Dispose handler for the Socket class, and can't seem to get
anything to work.
Any ideas what change I need to make to keep the connection open when my
And a follow-up, assuming keeping the connection open is possible, what are
the chances this "use an existing socket handle" feature could be included
into the main codebase? Asking users of my program to modify and recompile
mono isn't going to result in very happy people :) I'm using 3.12.1 but
would be happy to start over with the latest source on GitHub so I can
create a pull-request if it has a chance to be included.
View this message in context: http://mono.1490590.n4.nabble.com/Use-existing-socket-descriptor-tp4660658p4665729.html
Sent from the Mono - General mailing list archive at Nabble.com.
More information about the Mono-list