Merge pull request #601 from knocte/sock_improvements
authorMarek Safar <marek.safar@gmail.com>
Mon, 8 Apr 2013 10:00:28 +0000 (03:00 -0700)
committerMarek Safar <marek.safar@gmail.com>
Mon, 8 Apr 2013 10:00:28 +0000 (03:00 -0700)
 [System.Net.Sockets] Specify 'timeout' in the exception msg of the Receive(buf) overload

mcs/class/System/System.Net.Sockets/Socket.cs
mono/io-layer/sockets.c

index cc9e0f618f686a96cfd8317461abbc4e3cb86ed8..a453d70e43fa9043f3e0ffd85690e57974f9b99e 100644 (file)
@@ -11,7 +11,6 @@
 //    http://www.myelin.co.nz
 // (c) 2004-2011 Novell, Inc. (http://www.novell.com)
 //
-
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -55,6 +54,8 @@ namespace System.Net.Sockets
                private bool useoverlappedIO;
                private const int SOCKET_CLOSED = 10004;
 
+               private static readonly string timeout_exc_msg = "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond";
+
                static void AddSockets (List<Socket> sockets, IList list, string name)
                {
                        if (list != null) {
@@ -1494,20 +1495,7 @@ namespace System.Net.Sockets
 
                public int Receive (byte [] buffer)
                {
-                       if (disposed && closed)
-                               throw new ObjectDisposedException (GetType ().ToString ());
-
-                       if (buffer == null)
-                               throw new ArgumentNullException ("buffer");
-
-                       SocketError error;
-
-                       int ret = Receive_nochecks (buffer, 0, buffer.Length, SocketFlags.None, out error);
-                       
-                       if (error != SocketError.Success)
-                               throw new SocketException ((int) error);
-
-                       return ret;
+                       return Receive (buffer, SocketFlags.None);
                }
 
                public int Receive (byte [] buffer, SocketFlags flags)
@@ -1524,7 +1512,7 @@ namespace System.Net.Sockets
                        
                        if (error != SocketError.Success) {
                                if (error == SocketError.WouldBlock && blocking) // This might happen when ReceiveTimeout is set
-                                       throw new SocketException ((int) error, "Operation timed out.");
+                                       throw new SocketException ((int) error, timeout_exc_msg);
                                throw new SocketException ((int) error);
                        }
 
@@ -1547,7 +1535,7 @@ namespace System.Net.Sockets
                        
                        if (error != SocketError.Success) {
                                if (error == SocketError.WouldBlock && blocking) // This might happen when ReceiveTimeout is set
-                                       throw new SocketException ((int) error, "Operation timed out.");
+                                       throw new SocketException ((int) error, timeout_exc_msg);
                                throw new SocketException ((int) error);
                        }
 
@@ -1570,7 +1558,7 @@ namespace System.Net.Sockets
                        
                        if (error != SocketError.Success) {
                                if (error == SocketError.WouldBlock && blocking) // This might happen when ReceiveTimeout is set
-                                       throw new SocketException ((int) error, "Operation timed out.");
+                                       throw new SocketException ((int) error, timeout_exc_msg);
                                throw new SocketException ((int) error);
                        }
 
@@ -1709,7 +1697,7 @@ namespace System.Net.Sockets
                                        connected = false;
                                else if (err == SocketError.WouldBlock && blocking) { // This might happen when ReceiveTimeout is set
                                        if (throwOnError)       
-                                               throw new SocketException ((int) SocketError.TimedOut, "Operation timed out");
+                                               throw new SocketException ((int) SocketError.TimedOut, timeout_exc_msg);
                                        error = (int) SocketError.TimedOut;
                                        return 0;
                                }
index 285a1798e743ea5830b977d38824340088af206e..db8eff27302779a276aa6d285de1d9929d29745a 100644 (file)
@@ -902,6 +902,7 @@ guint32 _wapi_socket(int domain, int type, int protocol, void *unused,
        if (fd == -1 && domain == AF_INET && type == SOCK_RAW &&
            protocol == 0) {
                /* Retry with protocol == 4 (see bug #54565) */
+               // https://bugzilla.novell.com/show_bug.cgi?id=MONO54565
                socket_handle.protocol = 4;
                fd = socket (AF_INET, SOCK_RAW, 4);
        }
@@ -927,6 +928,7 @@ guint32 _wapi_socket(int domain, int type, int protocol, void *unused,
 
        /* .net seems to set this by default for SOCK_STREAM, not for
         * SOCK_DGRAM (see bug #36322)
+        * https://bugzilla.novell.com/show_bug.cgi?id=MONO36322
         *
         * It seems winsock has a rather different idea of what
         * SO_REUSEADDR means.  If it's set, then a new socket can be
@@ -937,6 +939,7 @@ guint32 _wapi_socket(int domain, int type, int protocol, void *unused,
         * behaves as though any other system would when SO_REUSEADDR
         * is true, so we don't need to do anything else here.  See
         * bug 53992.
+        * https://bugzilla.novell.com/show_bug.cgi?id=MONO53992
         */
        {
                int ret, true = 1;