From ff5956eacbdcab4262cf5f40c5afdc873ecc1ac3 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Thu, 16 Feb 2017 07:18:12 -0500 Subject: [PATCH] [socket] Add EPROTOTYPE error case (#4391) Fixes bug https://bugzilla.xamarin.com/show_bug.cgi?id=52549 --- .../Test/System.Net.Sockets/SocketTest.cs | 23 +++++++++++++++++++ mono/metadata/w32error.h | 1 + mono/metadata/w32socket-unix.c | 3 +++ 3 files changed, 27 insertions(+) diff --git a/mcs/class/System/Test/System.Net.Sockets/SocketTest.cs b/mcs/class/System/Test/System.Net.Sockets/SocketTest.cs index 7a0851912ea..bce47bcbf0d 100755 --- a/mcs/class/System/Test/System.Net.Sockets/SocketTest.cs +++ b/mcs/class/System/Test/System.Net.Sockets/SocketTest.cs @@ -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"); + } + } } } diff --git a/mono/metadata/w32error.h b/mono/metadata/w32error.h index 990ba3b3894..b02f814fdbf 100644 --- a/mono/metadata/w32error.h +++ b/mono/metadata/w32error.h @@ -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 diff --git a/mono/metadata/w32socket-unix.c b/mono/metadata/w32socket-unix.c index b4e3069d640..c10b2100368 100644 --- a/mono/metadata/w32socket-unix.c +++ b/mono/metadata/w32socket-unix.c @@ -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)); } -- 2.25.1