[Mono-devel-list] Patch for Async Socket Operations
Ankit Jain
radical at gmail.com
Fri Mar 11 01:23:39 EST 2005
Hi,
Attached is a patch for a new async sockets implementation. The
current implementation polls on a thread queued on the ThreadPool
(delegate's BeginInvoke) which becomes a problem when you have lots of
socket or socket operations and the threadpool reaches its limit!
In the proposed patch, whenever the first Begin*(async socket
operation, eg. BeginConnect/BeginReceive etc) is called a SocketIO
thread is spawned which select ()'s on that socket for the specified
operation, and the original Begin* call returns. Whenever that socket
becomes readable/writeable (depending on the operation :
receive/send/etc) the callback (if any..) specified by the original
caller is invoked to inform of completion of the operation. The caller
can now call End* to complete the operation and get the results.
If no callback was specified then the WaitHandle
(IAsyncResult.AsyncState) is .Set () so that the caller can use that
also to know of the completion status.
The SocketIO thread uses a self-pipe to be informed of any new sockets
to be added to the list for select (). So, its readList always has the
read-end of the pipe, and the Begin* call writes a byte to the
write-end of the pipe to indicate to the thread that a new socket is
available for addition.
The _wapi_FD_CLR, _wapi_FD_SET, _wapi_FD_ISSET functions in the mono
runtime accept only sockets (WAPI_HANDLE_SOCKET) so they have been
patched to support pipes (WAPI_HANDLE_PIPE). The second attached file
is for this patch.
Known problems:
- Select () scales to only 1024 sockets, but that can be fixed if we
use Poll .. other suggestions??
- It fails on a test that gonzalo uses. You can get the tests from cvs
:ext:anonymous at forgecvs1.novell.com:/cvsroot/gus
password for login is : anonymous
Regards,
Ankit
---
Blog :
Mono hacking : http://mono-nosip.blogspot.com
Personal : http://www.corewars.org/radical
-------------- next part --------------
A non-text attachment was scrubbed...
Name: async-socket.patch
Type: text/x-patch
Size: 22556 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20050311/fab9c11f/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mono-pipe.patch
Type: text/x-patch
Size: 1219 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20050311/fab9c11f/attachment-0001.bin
More information about the Mono-devel-list
mailing list