2008-12-20 Gonzalo Paniagua Javier <gonzalo@novell.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Sat, 20 Dec 2008 10:53:59 +0000 (10:53 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Sat, 20 Dec 2008 10:53:59 +0000 (10:53 -0000)
* Ping.cs: use the new internal method in Socket to avoid having to
throw exceptions when there's a timeout.

svn path=/trunk/mcs/; revision=121924

mcs/class/System/System.Net.NetworkInformation/ChangeLog
mcs/class/System/System.Net.NetworkInformation/Ping.cs

index fc559c36083d823e4e176143286493ff32e884f3..3cc5a37a0e835a65311e9c75da31d66602feb2d4 100644 (file)
@@ -1,4 +1,9 @@
 
+2008-12-20 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+       * Ping.cs: use the new internal method in Socket to avoid having to
+       throw exceptions when there's a timeout.
+
 2008-12-11 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
        * Ping.cs: close the socket in SendPrivileged. Use Buffer.BlockCopy
index a019edb42d11e4787b4281f5cd3b43107f4c9359..ed8544e4b9ff3dafa0a9509e4fce13f98d5afd34 100644 (file)
@@ -214,32 +214,29 @@ namespace System.Net.NetworkInformation {
                                // receive
                                bytes = new byte [100];
                                do {
-                                       try {
-                                               EndPoint endpoint = client;
-                                               int rc = s.ReceiveFrom (bytes, 100, SocketFlags.None, ref endpoint);
-                                               long rtt = (long) (DateTime.Now - sentTime).TotalMilliseconds;
-                                               int headerLength = (bytes [0] & 0xF) << 2;
-                                               int bodyLength = rc - headerLength;
-
-                                               if (!((IPEndPoint) endpoint).Address.Equals (target.Address)) // Ping reply to different request. discard it.
-                                                       continue;
-
-                                               IcmpMessage recv = new IcmpMessage (bytes, headerLength, bodyLength);
-                                               if (recv.Identifier != identifier)
-                                                       continue; // ping reply to different request. discard it.
-
-                                               return new PingReply (address, recv.Data, options, rtt, recv.IPStatus);
-                                       } catch (SocketException ex) {
-                                               IPStatus stat;
-                                               switch (ex.SocketErrorCode) {
-                                               case SocketError.TimedOut:
-                                                       stat = IPStatus.TimedOut;
-                                                       break;
-                                               default:
-                                                       throw new NotSupportedException (String.Format ("Unexpected socket error during ping request: {0}", ex.SocketErrorCode));
+                                       EndPoint endpoint = client;
+                                       int error = 0;
+                                       int rc = s.ReceiveFrom_nochecks_exc (bytes, 0, 100, SocketFlags.None,
+                                                       ref endpoint, false, out error);
+
+                                       if (error != 0) {
+                                               if (error == (int) SocketError.TimedOut) {
+                                                       return new PingReply (null, new byte [0], options, 0, IPStatus.TimedOut);
                                                }
-                                               return new PingReply (null, new byte [0], options, 0, stat);
+                                               throw new NotSupportedException (String.Format ("Unexpected socket error during ping request: {0}", error));
                                        }
+                                       long rtt = (long) (DateTime.Now - sentTime).TotalMilliseconds;
+                                       int headerLength = (bytes [0] & 0xF) << 2;
+                                       int bodyLength = rc - headerLength;
+
+                                       if (!((IPEndPoint) endpoint).Address.Equals (target.Address)) // Ping reply to different request. discard it.
+                                               continue;
+
+                                       IcmpMessage recv = new IcmpMessage (bytes, headerLength, bodyLength);
+                                       if (recv.Identifier != identifier)
+                                               continue; // ping reply to different request. discard it.
+
+                                       return new PingReply (address, recv.Data, options, rtt, recv.IPStatus);
                                } while (true);
                        }
                }