Author: gonzalo
Date: 2005-05-07 02:22:46 -0400 (Sat, 07 May 2005)
New Revision: 44192

Modified:
   trunk/mcs/class/System/System.Net.Sockets/ChangeLog
   trunk/mcs/class/System/System.Net.Sockets/Socket.cs
Log:
2005-05-07 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>

        * Socket.cs: see bug #74842, which is fixed with this patch for details
        and test cases on the blocking behavior of accept() when close() is
        called from another thread. The solution applied is to Abort the thread
        that is blocking in Accept_internal() when someone calls Close (), then
        reset the abort state if the socket is disposed and return the same
        error as MS (10004 - interrupted).



Modified: trunk/mcs/class/System/System.Net.Sockets/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Net.Sockets/ChangeLog 2005-05-07 05:22:49 UTC 
(rev 44191)
+++ trunk/mcs/class/System/System.Net.Sockets/ChangeLog 2005-05-07 06:22:46 UTC 
(rev 44192)
@@ -1,3 +1,12 @@
+2005-05-07 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+       * Socket.cs: see bug #74842, which is fixed with this patch for details
+       and test cases on the blocking behavior of accept() when close() is
+       called from another thread. The solution applied is to Abort the thread
+       that is blocking in Accept_internal() when someone calls Close (), then
+       reset the abort state if the socket is disposed and return the same
+       error as MS (10004 - interrupted).
+
 2005-05-06 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
 
        * Socket.cs: match MS behavior on SetSocketOption with a boolean

Modified: trunk/mcs/class/System/System.Net.Sockets/Socket.cs
===================================================================
--- trunk/mcs/class/System/System.Net.Sockets/Socket.cs 2005-05-07 05:22:49 UTC 
(rev 44191)
+++ trunk/mcs/class/System/System.Net.Sockets/Socket.cs 2005-05-07 06:22:46 UTC 
(rev 44192)
@@ -777,13 +777,25 @@
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                private extern static IntPtr Accept_internal(IntPtr sock,
                                                             out int error);
-               
+
+               Thread accept_thread;
                public Socket Accept() {
                        if (disposed && closed)
                                throw new ObjectDisposedException (GetType 
().ToString ());
 
-                       int error;
-                       IntPtr sock=Accept_internal(socket, out error);
+                       int error = 0;
+                       IntPtr sock = (IntPtr) (-1);
+                       accept_thread = Thread.CurrentThread;
+                       try {
+                               sock = Accept_internal(socket, out error);
+                       } catch (ThreadAbortException the) {
+                               if (disposed) {
+                                       Thread.ResetAbort ();
+                                       error = 10004;
+                               }
+                       } finally {
+                               accept_thread = null;
+                       }
 
                        if (error != 0) {
                                throw new SocketException (error);
@@ -1715,6 +1727,10 @@
                                IntPtr x = socket;
                                socket = (IntPtr) (-1);
                                Close_internal (x, out error);
+                               if (accept_thread != null) {
+                                       accept_thread.Abort ();
+                                       accept_thread = null;
+                               }
 
                                if (error != 0)
                                        throw new SocketException (error);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to