From 58ac3c61d11dd3b6a6004f4dc73cc789004801f4 Mon Sep 17 00:00:00 2001 From: Gonzalo Paniagua Javier Date: Sun, 16 Feb 2003 22:13:26 +0000 Subject: [PATCH] 2003-02-16 Gonzalo Paniagua Javier * 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 --- mcs/class/System/System.Net.Sockets/ChangeLog | 7 +++ 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 + + * 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 * 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; } } -- 2.25.1