[socket] Add EPROTOTYPE error case (#4391)
authorLudovic Henry <ludovic@xamarin.com>
Thu, 16 Feb 2017 12:18:12 +0000 (07:18 -0500)
committerGitHub <noreply@github.com>
Thu, 16 Feb 2017 12:18:12 +0000 (07:18 -0500)
Fixes bug https://bugzilla.xamarin.com/show_bug.cgi?id=52549

mcs/class/System/Test/System.Net.Sockets/SocketTest.cs
mono/metadata/w32error.h
mono/metadata/w32socket-unix.c

index 7a0851912ea37254f1112bfdf066d53932551903..bce47bcbf0dfc43890e39c8e81e064005e49a0ec 100755 (executable)
@@ -4675,6 +4675,29 @@ namespace MonoTests.System.Net.Sockets
 
                        Assert.IsTrue (mre.WaitOne (1000), "ConnectedAsync timeout");
                }
+
+               [Test] // Covers https://bugzilla.xamarin.com/show_bug.cgi?id=52549
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
+               public void SocketMismatchProtocol ()
+               {
+                       try {
+                               using (Socket socket = new Socket (AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Tcp));
+                               Assert.Fail ("#1");
+                       } catch (SocketException e) {
+                               // Only work on OSX
+                               // Assert.AreEqual(SocketError.ProtocolType, e.SocketErrorCode, "#2");
+                       }
+
+                       try {
+                               using (Socket socket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Udp));
+                               Assert.Fail ("#3");
+                       } catch (SocketException e) {
+                               // Only work on OSX
+                               // Assert.AreEqual(SocketError.ProtocolType, e.SocketErrorCode, "#4");
+                       }
+               }
        }
 }
 
index 990ba3b3894cd9f9bb7245a60e6b7a30fcff29ed..b02f814fdbfcc5709a2be77b2f879d7cd92e861d 100644 (file)
@@ -52,6 +52,7 @@
 #define WSAENOTSOCK                10038
 #define WSAEDESTADDRREQ            10039
 #define WSAEMSGSIZE                10040
+#define WSAEPROTOTYPE              10041
 #define WSAENOPROTOOPT             10042
 #define WSAEPROTONOSUPPORT         10043
 #define WSAESOCKTNOSUPPORT         10044
index b4e3069d6400ea315c6073912a9b6e426e92d175..c10b210036825595d708b2b77a814abe1b855c84 100644 (file)
@@ -1318,6 +1318,9 @@ mono_w32socket_convert_error (gint error)
        case ENETDOWN: return WSAENETDOWN;
 #endif
        case ENODEV: return WSAENETDOWN;
+#ifdef EPROTOTYPE
+       case EPROTOTYPE: return WSAEPROTOTYPE;
+#endif
        default:
                g_error ("%s: no translation into winsock error for (%d) \"%s\"", __func__, error, g_strerror (error));
        }