Quellcode durchsuchen

Merge pull request #3750 from marek-safar/socket

[System] More Socket pieces from referencesource
Marek Safar vor 9 Jahren
Ursprung
Commit
e95a1d4a00

+ 3 - 6
mcs/class/System/ReferenceSources/Logging.cs

@@ -1,12 +1,9 @@
 using System.Diagnostics;
 using System.Diagnostics;
 
 
 namespace System.Net {
 namespace System.Net {
-	class Logging {
-		internal static bool On {
-			get {
-				return false;
-			}
-		}
+	static class Logging
+	{
+		internal static readonly bool On = false;
 
 
 		internal static TraceSource Web {
 		internal static TraceSource Web {
 			get {
 			get {

+ 18 - 2
mcs/class/System/ReferenceSources/SettingsSectionInternal.cs

@@ -1,4 +1,5 @@
 using System.Net.Security;
 using System.Net.Security;
+using System.Net.Sockets;
 
 
 namespace System.Net.Configuration {
 namespace System.Net.Configuration {
 	sealed class SettingsSectionInternal
 	sealed class SettingsSectionInternal
@@ -16,8 +17,8 @@ namespace System.Net.Configuration {
 		internal UnicodeDecodingConformance WebUtilityUnicodeDecodingConformance = UnicodeDecodingConformance.Auto;
 		internal UnicodeDecodingConformance WebUtilityUnicodeDecodingConformance = UnicodeDecodingConformance.Auto;
 #endif
 #endif
 
 
-		internal bool HttpListenerUnescapeRequestUrl = true;
-
+		internal readonly bool HttpListenerUnescapeRequestUrl = true;
+		internal readonly IPProtectionLevel IPProtectionLevel = IPProtectionLevel.Unspecified;
 
 
 		internal bool UseNagleAlgorithm { get; set; }
 		internal bool UseNagleAlgorithm { get; set; }
 		internal bool Expect100Continue { get; set; }
 		internal bool Expect100Continue { get; set; }
@@ -26,5 +27,20 @@ namespace System.Net.Configuration {
 		internal bool EnableDnsRoundRobin { get; set; }
 		internal bool EnableDnsRoundRobin { get; set; }
 		internal bool CheckCertificateRevocationList { get; set; }
 		internal bool CheckCertificateRevocationList { get; set; }
 		internal EncryptionPolicy EncryptionPolicy { get; private set; }
 		internal EncryptionPolicy EncryptionPolicy { get; private set; }
+
+		internal bool Ipv6Enabled {
+			get {
+#if CONFIGURATION_DEP && !MOBILE
+				try {
+					var config = (SettingsSection) System.Configuration.ConfigurationManager.GetSection ("system.net/settings");
+					if (config != null)
+						return config.Ipv6.Enabled;
+				} catch {
+				}
+#endif
+
+				return true;
+			}
+		}
 	}
 	}
 }
 }

+ 39 - 127
mcs/class/System/System.Net.Sockets/Socket.cs

@@ -55,13 +55,6 @@ namespace System.Net.Sockets
 		const string TIMEOUT_EXCEPTION_MSG = "A connection attempt failed because the connected party did not properly respond" +
 		const string TIMEOUT_EXCEPTION_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";
 			"after a period of time, or established connection failed because connected host has failed to respond";
 
 
-		/*
-		 *	These two fields are looked up by name by the runtime, don't change
-		 *  their name without also updating the runtime code.
-		 */
-		static int ipv4_supported = -1;
-		static int ipv6_supported = -1;
-
 		/* true if we called Close_internal */
 		/* true if we called Close_internal */
 		bool is_closed;
 		bool is_closed;
 
 
@@ -98,80 +91,8 @@ namespace System.Net.Sockets
 		int m_IntCleanedUp;
 		int m_IntCleanedUp;
 		internal bool connect_in_progress;
 		internal bool connect_in_progress;
 
 
-		private static volatile bool s_LoggingEnabled = Logging.On;
-
 #region Constructors
 #region Constructors
 
 
-		static Socket ()
-		{
-			if (ipv4_supported == -1) {
-				try {
-					Socket tmp = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
-					tmp.Close();
-
-					ipv4_supported = 1;
-				} catch {
-					ipv4_supported = 0;
-				}
-			}
-
-			if (ipv6_supported == -1) {
-				// We need to put a try/catch around ConfigurationManager methods as will always throw an exception 
-				// when run in a mono embedded application.  This occurs as embedded applications do not have a setup
-				// for application config.  The exception is not thrown when called from a normal .NET application. 
-				//
-				// We, then, need to guard calls to the ConfigurationManager.  If the config is not found or throws an
-				// exception, will fall through to the existing Socket / API directly below in the code.
-				//
-				// Also note that catching ConfigurationErrorsException specifically would require library dependency
-				// System.Configuration, and wanted to avoid that.
-#if !MOBILE
-#if CONFIGURATION_DEP
-				try {
-					SettingsSection config;
-					config = (SettingsSection) System.Configuration.ConfigurationManager.GetSection ("system.net/settings");
-					if (config != null)
-						ipv6_supported = config.Ipv6.Enabled ? -1 : 0;
-				} catch {
-					ipv6_supported = -1;
-				}
-#else
-				try {
-					NetConfig config = System.Configuration.ConfigurationSettings.GetConfig("system.net/settings") as NetConfig;
-					if (config != null)
-						ipv6_supported = config.ipv6Enabled ? -1 : 0;
-				} catch {
-					ipv6_supported = -1;
-				}
-#endif
-#endif
-				if (ipv6_supported != 0) {
-					try {
-						Socket tmp = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
-						tmp.Close();
-
-						ipv6_supported = 1;
-					} catch {
-						ipv6_supported = 0;
-					}
-				}
-			}
-		}
-
-		public Socket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
-		{
-			this.addressFamily = addressFamily;
-			this.socketType = socketType;
-			this.protocolType = protocolType;
-
-			int error;
-			this.m_Handle = new SafeSocketHandle (Socket_internal (addressFamily, socketType, protocolType, out error), true);
-
-			if (error != 0)
-				throw new SocketException (error);
-
-			SocketDefaults ();
-		}
 
 
 		public Socket (SocketInformation socketInformation)
 		public Socket (SocketInformation socketInformation)
 		{
 		{
@@ -188,6 +109,8 @@ namespace System.Net.Sockets
 			this.is_bound = (ProtocolType) (int) result [3] != 0;
 			this.is_bound = (ProtocolType) (int) result [3] != 0;
 			this.m_Handle = new SafeSocketHandle ((IntPtr) (long) result [4], true);
 			this.m_Handle = new SafeSocketHandle ((IntPtr) (long) result [4], true);
 
 
+			InitializeSockets ();
+
 			SocketDefaults ();
 			SocketDefaults ();
 		}
 		}
 
 
@@ -200,6 +123,8 @@ namespace System.Net.Sockets
 			
 			
 			this.m_Handle = safe_handle;
 			this.m_Handle = safe_handle;
 			this.is_connected = true;
 			this.is_connected = true;
+
+			InitializeSockets ();	
 		}
 		}
 
 
 		void SocketDefaults ()
 		void SocketDefaults ()
@@ -236,54 +161,6 @@ namespace System.Net.Sockets
 
 
 #region Properties
 #region Properties
 
 
-		[ObsoleteAttribute ("Use OSSupportsIPv4 instead")]
-		public static bool SupportsIPv4 {
-			get { return ipv4_supported == 1; }
-		}
-
-		[ObsoleteAttribute ("Use OSSupportsIPv6 instead")]
-		public static bool SupportsIPv6 {
-			get { return ipv6_supported == 1; }
-		}
-
-#if MOBILE
-		public static bool OSSupportsIPv4 {
-			get { return ipv4_supported == 1; }
-		}
-#else
-		public static bool OSSupportsIPv4 {
-			get {
-				NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces ();
-
-				foreach (NetworkInterface adapter in nics) {
-					if (adapter.Supports (NetworkInterfaceComponent.IPv4))
-						return true;
-				}
-
-				return false;
-			}
-		}
-#endif
-
-#if MOBILE
-		public static bool OSSupportsIPv6 {
-			get { return ipv6_supported == 1; }
-		}
-#else
-		public static bool OSSupportsIPv6 {
-			get {
-				NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces ();
-
-				foreach (NetworkInterface adapter in nics) {
-					if (adapter.Supports (NetworkInterfaceComponent.IPv6))
-						return true;
-				}
-
-				return false;
-			}
-		}
-#endif
-
 		public int Available {
 		public int Available {
 			get {
 			get {
 				ThrowIfDisposedAndClosed ();
 				ThrowIfDisposedAndClosed ();
@@ -2918,6 +2795,41 @@ m_Handle, buffer, offset + sent, size - sent, socketFlags, out nativeError, is_b
 
 
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
 		internal static extern bool SupportsPortReuse (ProtocolType proto);
 		internal static extern bool SupportsPortReuse (ProtocolType proto);
+
+		internal static int FamilyHint {
+			get {
+				// Returns one of
+				//	MONO_HINT_UNSPECIFIED		= 0,
+				//	MONO_HINT_IPV4				= 1,
+				//	MONO_HINT_IPV6				= 2,
+
+				int hint = 0;
+				if (OSSupportsIPv4) {
+					hint = 1;
+				}
+
+				if (OSSupportsIPv6) {
+					hint = hint == 0 ? 2 : 0;
+				}
+
+				return hint;
+			}
+		}
+
+		static bool IsProtocolSupported (NetworkInterfaceComponent networkInterface)
+		{
+#if MOBILE
+			return true;
+#else
+			var nics = NetworkInterface.GetAllNetworkInterfaces ();
+			foreach (var adapter in nics) {
+				if (adapter.Supports (networkInterface))
+					return true;
+			}
+
+			return false;
+#endif
+		}
 	}
 	}
 }
 }
 
 

+ 4 - 4
mcs/class/System/System.Net/Dns.cs

@@ -295,10 +295,10 @@ namespace System.Net {
 
 
 
 
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
-		private extern static bool GetHostByName_internal(string host, out string h_name, out string[] h_aliases, out string[] h_addr_list);
+		private extern static bool GetHostByName_internal(string host, out string h_name, out string[] h_aliases, out string[] h_addr_list, int hint);
 
 
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
-		private extern static bool GetHostByAddr_internal(string addr, out string h_name, out string[] h_aliases, out string[] h_addr_list);
+		private extern static bool GetHostByAddr_internal(string addr, out string h_name, out string[] h_aliases, out string[] h_addr_list, int hint);
 
 
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
 		private extern static bool GetHostName_internal(out string h_name);
 		private extern static bool GetHostName_internal(out string h_name);
@@ -372,7 +372,7 @@ namespace System.Net {
 
 
 			string h_name;
 			string h_name;
 			string[] h_aliases, h_addrlist;
 			string[] h_aliases, h_addrlist;
-			bool ret = GetHostByAddr_internal(address, out h_name, out h_aliases, out h_addrlist);
+			bool ret = GetHostByAddr_internal(address, out h_name, out h_aliases, out h_addrlist, Socket.FamilyHint);
 			if (!ret)
 			if (!ret)
 				Error_11001 (address);
 				Error_11001 (address);
 			return (hostent_to_IPHostEntry (address, h_name, h_aliases, h_addrlist));
 			return (hostent_to_IPHostEntry (address, h_name, h_aliases, h_addrlist));
@@ -434,7 +434,7 @@ namespace System.Net {
 			string h_name;
 			string h_name;
 			string[] h_aliases, h_addrlist;
 			string[] h_aliases, h_addrlist;
 
 
-			bool ret = GetHostByName_internal(hostName, out h_name, out h_aliases, out h_addrlist);
+			bool ret = GetHostByName_internal(hostName, out h_name, out h_aliases, out h_addrlist, Socket.FamilyHint);
 			if (ret == false)
 			if (ret == false)
 				Error_11001 (hostName);
 				Error_11001 (hostName);
 
 

+ 1 - 1
mcs/class/corlib/System/Environment.cs

@@ -57,7 +57,7 @@ namespace System {
 		 * of icalls, do not require an increment.
 		 * of icalls, do not require an increment.
 		 */
 		 */
 #pragma warning disable 169
 #pragma warning disable 169
-		private const int mono_corlib_version = 159;
+		private const int mono_corlib_version = 160;
 #pragma warning restore 169
 #pragma warning restore 169
 
 
 		[ComVisible (true)]
 		[ComVisible (true)]

+ 30 - 9
mcs/class/referencesource/System/net/System/Net/Sockets/Socket.cs

@@ -108,12 +108,15 @@ namespace System.Net.Sockets {
         private SocketAddress   m_PermittedRemoteAddress;
         private SocketAddress   m_PermittedRemoteAddress;
 
 
         private DynamicWinsockMethods m_DynamicWinsockMethods;
         private DynamicWinsockMethods m_DynamicWinsockMethods;
+#endif // !MONO
 
 
         private static object s_InternalSyncObject;
         private static object s_InternalSyncObject;
+#if !MONO
         private int m_CloseTimeout = Socket.DefaultCloseTimeout;
         private int m_CloseTimeout = Socket.DefaultCloseTimeout;
         private int m_IntCleanedUp;                 // 0 if not completed >0 otherwise.
         private int m_IntCleanedUp;                 // 0 if not completed >0 otherwise.
         private const int microcnv = 1000000;
         private const int microcnv = 1000000;
         private readonly static int protocolInformationSize = Marshal.SizeOf(typeof(UnsafeNclNativeMethods.OSSOCK.WSAPROTOCOL_INFO));
         private readonly static int protocolInformationSize = Marshal.SizeOf(typeof(UnsafeNclNativeMethods.OSSOCK.WSAPROTOCOL_INFO));
+#endif // !MONO
 
 
         internal static volatile bool s_SupportsIPv4;
         internal static volatile bool s_SupportsIPv4;
         internal static volatile bool s_SupportsIPv6;
         internal static volatile bool s_SupportsIPv6;
@@ -124,7 +127,6 @@ namespace System.Net.Sockets {
 #if !FEATURE_PAL // perfcounter
 #if !FEATURE_PAL // perfcounter
         internal static volatile bool s_PerfCountersEnabled;
         internal static volatile bool s_PerfCountersEnabled;
 #endif
 #endif
-#endif // !MONO
 
 
 //************* constructors *************************
 //************* constructors *************************
 
 
@@ -136,7 +138,6 @@ namespace System.Net.Sockets {
             DualMode = true;
             DualMode = true;
         }
         }
 
 
-#if !MONO
         /// <devdoc>
         /// <devdoc>
         ///    <para>
         ///    <para>
         ///       Initializes a new instance of the <see cref='Sockets.Socket'/> class.
         ///       Initializes a new instance of the <see cref='Sockets.Socket'/> class.
@@ -146,10 +147,16 @@ namespace System.Net.Sockets {
             s_LoggingEnabled = Logging.On;
             s_LoggingEnabled = Logging.On;
             if(s_LoggingEnabled)Logging.Enter(Logging.Sockets, this, "Socket", addressFamily);
             if(s_LoggingEnabled)Logging.Enter(Logging.Sockets, this, "Socket", addressFamily);
             InitializeSockets();
             InitializeSockets();
+
+#if MONO
+            int error;
+            m_Handle = new SafeSocketHandle (Socket_internal (addressFamily, socketType, protocolType, out error), true);
+#else
             m_Handle = SafeCloseSocket.CreateWSASocket(
             m_Handle = SafeCloseSocket.CreateWSASocket(
                     addressFamily,
                     addressFamily,
                     socketType,
                     socketType,
                     protocolType);
                     protocolType);
+#endif
 
 
             if (m_Handle.IsInvalid) {
             if (m_Handle.IsInvalid) {
                 //
                 //
@@ -167,10 +174,14 @@ namespace System.Net.Sockets {
                 SetIPProtectionLevel(defaultProtectionLevel);
                 SetIPProtectionLevel(defaultProtectionLevel);
             }
             }
 
 
+#if MONO
+            SocketDefaults ();
+#endif
+
             if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "Socket", null);
             if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "Socket", null);
         }
         }
 
 
-
+#if !MONO
         public Socket(SocketInformation socketInformation) {
         public Socket(SocketInformation socketInformation) {
             s_LoggingEnabled = Logging.On;
             s_LoggingEnabled = Logging.On;
             if(s_LoggingEnabled)Logging.Enter(Logging.Sockets, this, "Socket", addressFamily);
             if(s_LoggingEnabled)Logging.Enter(Logging.Sockets, this, "Socket", addressFamily);
@@ -288,7 +299,7 @@ namespace System.Net.Sockets {
             protocolType = Sockets.ProtocolType.Unknown;
             protocolType = Sockets.ProtocolType.Unknown;
             if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "Socket", null);
             if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "Socket", null);
         }
         }
-
+#endif
 
 
 
 
 //************* properties *************************
 //************* properties *************************
@@ -339,7 +350,7 @@ namespace System.Net.Sockets {
             }
             }
         }
         }
 
 
-
+#if !MONO
         /// <devdoc>
         /// <devdoc>
         ///    <para>
         ///    <para>
         ///       Gets the amount of data pending in the network's input buffer that can be
         ///       Gets the amount of data pending in the network's input buffer that can be
@@ -5716,7 +5727,7 @@ namespace System.Net.Sockets {
             InternalSetBlocking(willBlockInternal);
             InternalSetBlocking(willBlockInternal);
             if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "Shutdown", "");
             if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "Shutdown", "");
         }
         }
-
+#endif
 
 
 
 
 //************* internal and private properties *************************
 //************* internal and private properties *************************
@@ -5731,6 +5742,7 @@ namespace System.Net.Sockets {
             }
             }
         }
         }
 
 
+#if !MONO
         private CacheSet Caches
         private CacheSet Caches
         {
         {
             get
             get
@@ -6004,13 +6016,14 @@ namespace System.Net.Sockets {
 
 
             return socketAddress;
             return socketAddress;
         }
         }
-
+#endif
 
 
         internal static void InitializeSockets() {
         internal static void InitializeSockets() {
             if (!s_Initialized) {
             if (!s_Initialized) {
                 lock(InternalSyncObject){
                 lock(InternalSyncObject){
                     if (!s_Initialized) {
                     if (!s_Initialized) {
 
 
+#if !MONO
                         WSAData wsaData = new WSAData();
                         WSAData wsaData = new WSAData();
 
 
                         SocketError errorCode =
                         SocketError errorCode =
@@ -6025,6 +6038,7 @@ namespace System.Net.Sockets {
                             // WSAStartup does not set LastWin32Error
                             // WSAStartup does not set LastWin32Error
                             throw new SocketException(errorCode);
                             throw new SocketException(errorCode);
                         }
                         }
+#endif
 
 
 #if !FEATURE_PAL
 #if !FEATURE_PAL
                         //
                         //
@@ -6045,6 +6059,10 @@ namespace System.Net.Sockets {
                         bool   ipv4      = true; 
                         bool   ipv4      = true; 
                         bool   ipv6      = true; 
                         bool   ipv6      = true; 
 
 
+#if MONO
+                        ipv4 = IsProtocolSupported (System.Net.NetworkInformation.NetworkInterfaceComponent.IPv4);
+                        ipv6 = IsProtocolSupported (System.Net.NetworkInformation.NetworkInterfaceComponent.IPv6);
+#else
                         SafeCloseSocket.InnerSafeCloseSocket socketV4 = 
                         SafeCloseSocket.InnerSafeCloseSocket socketV4 = 
                                                              UnsafeNclNativeMethods.OSSOCK.WSASocket(
                                                              UnsafeNclNativeMethods.OSSOCK.WSASocket(
                                                                     AddressFamily.InterNetwork, 
                                                                     AddressFamily.InterNetwork, 
@@ -6078,7 +6096,7 @@ namespace System.Net.Sockets {
                         socketV6.Close();
                         socketV6.Close();
 
 
                         // <
                         // <
-
+#endif // MONO
 
 
 
 
 #if COMNET_DISABLEIPV6
 #if COMNET_DISABLEIPV6
@@ -6112,16 +6130,19 @@ namespace System.Net.Sockets {
 
 
                         // Cache some settings locally.
                         // Cache some settings locally.
 
 
+#if !MONO
 #if !FEATURE_PAL // perfcounter
 #if !FEATURE_PAL // perfcounter
                         s_PerfCountersEnabled = NetworkingPerfCounters.Instance.Enabled;
                         s_PerfCountersEnabled = NetworkingPerfCounters.Instance.Enabled;
 #endif
 #endif
+#endif
+
                         s_Initialized = true;
                         s_Initialized = true;
                     }
                     }
                 }
                 }
             }
             }
         }
         }
 
 
-
+#if !MONO
         internal void InternalConnect(EndPoint remoteEP)
         internal void InternalConnect(EndPoint remoteEP)
         {
         {
             EndPoint endPointSnapshot = remoteEP;
             EndPoint endPointSnapshot = remoteEP;

+ 1 - 1
mono/metadata/appdomain.c

@@ -84,7 +84,7 @@
  * Changes which are already detected at runtime, like the addition
  * Changes which are already detected at runtime, like the addition
  * of icalls, do not require an increment.
  * of icalls, do not require an increment.
  */
  */
-#define MONO_CORLIB_VERSION 159
+#define MONO_CORLIB_VERSION 160
 
 
 typedef struct
 typedef struct
 {
 {

+ 0 - 1
mono/metadata/domain-internals.h

@@ -339,7 +339,6 @@ struct _MonoDomain {
 	/* Needed by Thread:GetDomainID() */
 	/* Needed by Thread:GetDomainID() */
 	gint32             domain_id;
 	gint32             domain_id;
 	gint32             shadow_serial;
 	gint32             shadow_serial;
-	unsigned char      inet_family_hint; // used in socket-io.c as a cache
 	GSList             *domain_assemblies;
 	GSList             *domain_assemblies;
 	MonoAssembly       *entry_assembly;
 	MonoAssembly       *entry_assembly;
 	char               *friendly_name;
 	char               *friendly_name;

+ 2 - 2
mono/metadata/icall-def.h

@@ -681,8 +681,8 @@ ICALL(MCATTR_3, "IsDefinedInternal", custom_attrs_defined_internal)
 
 
 #ifndef DISABLE_SOCKETS
 #ifndef DISABLE_SOCKETS
 ICALL_TYPE(NDNS, "System.Net.Dns", NDNS_1)
 ICALL_TYPE(NDNS, "System.Net.Dns", NDNS_1)
-ICALL(NDNS_1, "GetHostByAddr_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByAddr_internal)
-ICALL(NDNS_2, "GetHostByName_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByName_internal)
+ICALL(NDNS_1, "GetHostByAddr_internal(string,string&,string[]&,string[]&,int)", ves_icall_System_Net_Dns_GetHostByAddr_internal)
+ICALL(NDNS_2, "GetHostByName_internal(string,string&,string[]&,string[]&,int)", ves_icall_System_Net_Dns_GetHostByName_internal)
 ICALL(NDNS_3, "GetHostName_internal(string&)", ves_icall_System_Net_Dns_GetHostName_internal)
 ICALL(NDNS_3, "GetHostName_internal(string&)", ves_icall_System_Net_Dns_GetHostName_internal)
 
 
 #if defined(PLATFORM_MACOSX) || defined(PLATFORM_BSD)
 #if defined(PLATFORM_MACOSX) || defined(PLATFORM_BSD)

+ 3 - 95
mono/metadata/socket-io.c

@@ -591,61 +591,6 @@ get_socket_assembly (void)
 	return domain->socket_assembly;
 	return domain->socket_assembly;
 }
 }
 
 
-static gint32
-get_family_hint (MonoError *error)
-{
-	MonoDomain *domain = mono_domain_get ();
-
-	mono_error_init (error);
-
-	if (!domain->inet_family_hint) {
-		MonoImage *socket_assembly;
-		MonoClass *socket_class;
-		MonoClassField *ipv6_field, *ipv4_field;
-		gint32 ipv6_enabled = -1, ipv4_enabled = -1;
-		MonoVTable *vtable;
-
-		socket_assembly = get_socket_assembly ();
-		g_assert (socket_assembly);
-
-		socket_class = mono_class_load_from_name (socket_assembly, "System.Net.Sockets", "Socket");
-
-		ipv4_field = mono_class_get_field_from_name (socket_class, "ipv4_supported");
-		g_assert (ipv4_field);
-
-		ipv6_field = mono_class_get_field_from_name (socket_class, "ipv6_supported");
-		g_assert (ipv6_field);
-
-		vtable = mono_class_vtable (mono_domain_get (), socket_class);
-		g_assert (vtable);
-
-		mono_runtime_class_init_full (vtable, error);
-		return_val_if_nok (error, -1);
-
-		mono_field_static_get_value_checked (vtable, ipv4_field, &ipv4_enabled, error);
-		return_val_if_nok (error, -1);
-		mono_field_static_get_value_checked (vtable, ipv6_field, &ipv6_enabled, error);
-		return_val_if_nok (error, -1);
-
-		mono_domain_lock (domain);
-		if (ipv4_enabled == 1 && ipv6_enabled == 1) {
-			domain->inet_family_hint = 1;
-		} else if (ipv4_enabled == 1) {
-			domain->inet_family_hint = 2;
-		} else {
-			domain->inet_family_hint = 3;
-		}
-		mono_domain_unlock (domain);
-	}
-	switch (domain->inet_family_hint) {
-	case 1: return PF_UNSPEC;
-	case 2: return PF_INET;
-	case 3: return PF_INET6;
-	default:
-		return PF_UNSPEC;
-	}
-}
-
 gpointer
 gpointer
 ves_icall_System_Net_Sockets_Socket_Socket_internal (MonoObject *this_obj, gint32 family, gint32 type, gint32 proto, gint32 *werror)
 ves_icall_System_Net_Sockets_Socket_Socket_internal (MonoObject *this_obj, gint32 family, gint32 type, gint32 proto, gint32 *werror)
 {
 {
@@ -2640,50 +2585,18 @@ leave2:
 	return is_ok (error);
 	return is_ok (error);
 }
 }
 
 
-static int
-get_addrinfo_family_hint (MonoError *error)
-{
-	int hint;
-
-	mono_error_init (error);
-
-	hint = get_family_hint (error);
-	return_val_if_nok (error, 0);
-
-	switch (hint) {
-	case PF_UNSPEC:
-		return MONO_HINT_UNSPECIFIED;
-	case PF_INET:
-		return MONO_HINT_IPV4;
-#ifdef PF_INET6
-	case PF_INET6:
-		return MONO_HINT_IPV6;
-#endif
-	default:
-		g_error ("invalid hint");
-		return 0;
-	}
-}
-
 MonoBoolean
 MonoBoolean
-ves_icall_System_Net_Dns_GetHostByName_internal (MonoString *host, MonoString **h_name, MonoArray **h_aliases, MonoArray **h_addr_list)
+ves_icall_System_Net_Dns_GetHostByName_internal (MonoString *host, MonoString **h_name, MonoArray **h_aliases, MonoArray **h_addr_list, gint32 hint)
 {
 {
 	MonoError error;
 	MonoError error;
 	gboolean add_local_ips = FALSE, add_info_ok = TRUE;
 	gboolean add_local_ips = FALSE, add_info_ok = TRUE;
 	gchar this_hostname [256];
 	gchar this_hostname [256];
 	MonoAddressInfo *info = NULL;
 	MonoAddressInfo *info = NULL;
-	int hint;
 
 
 	char *hostname = mono_string_to_utf8_checked (host, &error);
 	char *hostname = mono_string_to_utf8_checked (host, &error);
 	if (mono_error_set_pending_exception (&error))
 	if (mono_error_set_pending_exception (&error))
 		return FALSE;
 		return FALSE;
 
 
-	hint = get_addrinfo_family_hint (&error);
-	if (!mono_error_ok (&error)) {
-		mono_error_set_pending_exception (&error);
-		return FALSE;
-	}
-
 	if (*hostname == '\0') {
 	if (*hostname == '\0') {
 		add_local_ips = TRUE;
 		add_local_ips = TRUE;
 		*h_name = host;
 		*h_name = host;
@@ -2718,14 +2631,14 @@ ves_icall_System_Net_Dns_GetHostByName_internal (MonoString *host, MonoString **
 }
 }
 
 
 MonoBoolean
 MonoBoolean
-ves_icall_System_Net_Dns_GetHostByAddr_internal (MonoString *addr, MonoString **h_name, MonoArray **h_aliases, MonoArray **h_addr_list)
+ves_icall_System_Net_Dns_GetHostByAddr_internal (MonoString *addr, MonoString **h_name, MonoArray **h_aliases, MonoArray **h_addr_list, gint32 hint)
 {
 {
 	char *address;
 	char *address;
 	struct sockaddr_in saddr;
 	struct sockaddr_in saddr;
 	struct sockaddr_in6 saddr6;
 	struct sockaddr_in6 saddr6;
 	MonoAddressInfo *info = NULL;
 	MonoAddressInfo *info = NULL;
 	MonoError error;
 	MonoError error;
-	gint32 family, hint;
+	gint32 family;
 	gchar hostname [NI_MAXHOST] = { 0 };
 	gchar hostname [NI_MAXHOST] = { 0 };
 	gboolean ret;
 	gboolean ret;
 
 
@@ -2772,11 +2685,6 @@ ves_icall_System_Net_Dns_GetHostByAddr_internal (MonoString *addr, MonoString **
 	if (!ret)
 	if (!ret)
 		return FALSE;
 		return FALSE;
 
 
-	hint = get_addrinfo_family_hint (&error);
-	if (!mono_error_ok (&error)) {
-		mono_error_set_pending_exception (&error);
-		return FALSE;
-	}
 	if (mono_get_address_info (hostname, 0, hint | MONO_HINT_CANONICAL_NAME | MONO_HINT_CONFIGURED_ONLY, &info) != 0)
 	if (mono_get_address_info (hostname, 0, hint | MONO_HINT_CANONICAL_NAME | MONO_HINT_CONFIGURED_ONLY, &info) != 0)
 		return FALSE;
 		return FALSE;
 
 

+ 2 - 2
mono/metadata/socket-io.h

@@ -182,8 +182,8 @@ extern void ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal(SOC
 extern void ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal(SOCKET sock, gint32 level, gint32 name, MonoArray **byte_val, gint32 *error);
 extern void ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal(SOCKET sock, gint32 level, gint32 name, MonoArray **byte_val, gint32 *error);
 extern void ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal(SOCKET sock, gint32 level, gint32 name, MonoObject *obj_val, MonoArray *byte_val, gint32 int_val, gint32 *error);
 extern void ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal(SOCKET sock, gint32 level, gint32 name, MonoObject *obj_val, MonoArray *byte_val, gint32 int_val, gint32 *error);
 extern int ves_icall_System_Net_Sockets_Socket_IOControl_internal (SOCKET sock, gint32 code, MonoArray *input, MonoArray *output, gint32 *error);
 extern int ves_icall_System_Net_Sockets_Socket_IOControl_internal (SOCKET sock, gint32 code, MonoArray *input, MonoArray *output, gint32 *error);
-extern MonoBoolean ves_icall_System_Net_Dns_GetHostByName_internal(MonoString *host, MonoString **h_name, MonoArray **h_aliases, MonoArray **h_addr_list);
-extern MonoBoolean ves_icall_System_Net_Dns_GetHostByAddr_internal(MonoString *addr, MonoString **h_name, MonoArray **h_aliases, MonoArray **h_addr_list);
+extern MonoBoolean ves_icall_System_Net_Dns_GetHostByName_internal(MonoString *host, MonoString **h_name, MonoArray **h_aliases, MonoArray **h_addr_list, gint32 hint);
+extern MonoBoolean ves_icall_System_Net_Dns_GetHostByAddr_internal(MonoString *addr, MonoString **h_name, MonoArray **h_aliases, MonoArray **h_addr_list, gint32 hint);
 extern MonoBoolean ves_icall_System_Net_Dns_GetHostName_internal(MonoString **h_name);
 extern MonoBoolean ves_icall_System_Net_Dns_GetHostName_internal(MonoString **h_name);
 extern MonoBoolean ves_icall_System_Net_Sockets_Socket_Poll_internal (SOCKET sock, gint mode, gint timeout, gint32 *error);
 extern MonoBoolean ves_icall_System_Net_Sockets_Socket_Poll_internal (SOCKET sock, gint mode, gint timeout, gint32 *error);
 extern void ves_icall_System_Net_Sockets_Socket_Disconnect_internal(SOCKET sock, MonoBoolean reuse, gint32 *error);
 extern void ves_icall_System_Net_Sockets_Socket_Disconnect_internal(SOCKET sock, MonoBoolean reuse, gint32 *error);