diff options
author | Gonzalo Paniagua Javier <gonzalo.mono@gmail.com> | 2003-02-17 01:13:26 +0300 |
---|---|---|
committer | Gonzalo Paniagua Javier <gonzalo.mono@gmail.com> | 2003-02-17 01:13:26 +0300 |
commit | 58ac3c61d11dd3b6a6004f4dc73cc789004801f4 (patch) | |
tree | f35eb92ed3714af13543d72f12e7deed49db9491 /mcs/class/System/System.Net.Sockets | |
parent | 022abadb2ed23f255e05bfdbdd5e9980944179d0 (diff) |
2003-02-16 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* Socket.cs: make Worker.Connect and Receive work with non-blocking
sockets. May be Receive* and Send* in Worker need to do the same. I'll
wait for bug reports. Set IsCompleted to true before invoking the end
callback. Fixes bug #38136.
svn path=/trunk/mcs/; revision=11629
Diffstat (limited to 'mcs/class/System/System.Net.Sockets')
-rw-r--r-- | mcs/class/System/System.Net.Sockets/ChangeLog | 7 | ||||
-rw-r--r-- | mcs/class/System/System.Net.Sockets/Socket.cs | 56 |
2 files changed, 57 insertions, 6 deletions
diff --git a/mcs/class/System/System.Net.Sockets/ChangeLog b/mcs/class/System/System.Net.Sockets/ChangeLog index 22960f131ab..b34f3138f96 100644 --- a/mcs/class/System/System.Net.Sockets/ChangeLog +++ b/mcs/class/System/System.Net.Sockets/ChangeLog @@ -1,3 +1,10 @@ +2003-02-16 Gonzalo Paniagua Javier <gonzalo@ximian.com> + + * Socket.cs: make Worker.Connect and Receive work with non-blocking + sockets. May be Receive* and Send* in Worker need to do the same. I'll + wait for bug reports. Set IsCompleted to true before invoking the end + callback. Fixes bug #38136. + 2003-01-23 Gonzalo Paniagua Javier <gonzalo@ximian.com> * NetworkStream.cs: the check for disposed should not be done in the diff --git a/mcs/class/System/System.Net.Sockets/Socket.cs b/mcs/class/System/System.Net.Sockets/Socket.cs index 36086ef24b5..f430be427ac 100644 --- a/mcs/class/System/System.Net.Sockets/Socket.cs +++ b/mcs/class/System/System.Net.Sockets/Socket.cs @@ -133,8 +133,8 @@ namespace System.Net.Sockets private void End() { ((ManualResetEvent)result.AsyncWaitHandle).Set(); - callback(result); result.IsCompleted=true; + callback(result); } public void Accept() { @@ -146,16 +146,60 @@ namespace System.Net.Sockets public void Connect() { lock(result) { - socket.Connect(endpoint); - End(); + if (socket.Blocking) { + socket.Connect(endpoint); + End (); + return; + } + + SocketException rethrow = null; + try { + socket.Connect (endpoint); + } catch (SocketException e) { + //WSAEINPROGRESS + if (e.NativeErrorCode != 10036) + throw; + + socket.Poll (-1, SelectMode.SelectWrite); + try { + socket.Connect (endpoint); + } catch (SocketException e2) { + rethrow = e2; + } + } + End (); + if (rethrow != null) + throw rethrow; } } public void Receive() { lock(result) { - total=socket.Receive(buffer, offset, - size, sockflags); - End(); + if (socket.Blocking) { + total=socket.Receive(buffer, offset, + size, sockflags); + End(); + return; + } + + SocketException rethrow = null; + try { + total = socket.Receive (buffer, offset, size, sockflags); + } catch (SocketException e) { + //WSAEWOULDBLOCK + if (e.NativeErrorCode != 10035) + throw; + + socket.Poll (-1, SelectMode.SelectRead); + try { + total = socket.Receive (buffer, offset, size, sockflags); + } catch (SocketException e2) { + rethrow = e2; + } + } + End (); + if (rethrow != null) + throw rethrow; } } |