Merge pull request #495 from nicolas-raoul/fix-for-issue2907-with-no-formatting-changes
[mono.git] / mono / metadata / socket-io.c
index c71fd74a328436ea463acc1651363c70bb5c5a3d..5a6848ea1c1ac28cff0037795a399caf63eadd94 100644 (file)
@@ -50,6 +50,7 @@
 #include <mono/metadata/threadpool-internals.h>
 #include <mono/metadata/domain-internals.h>
 #include <mono/utils/mono-threads.h>
+#include <mono/utils/mono-memory-model.h>
 
 #include <time.h>
 #ifdef HAVE_SYS_TIME_H
@@ -664,43 +665,22 @@ static gint32 convert_sockopt_level_and_name(MonoSocketOptionLevel mono_level,
 
 static MonoImage *get_socket_assembly (void)
 {
-       static const char *version = NULL;
-       static gboolean moonlight;
        MonoDomain *domain = mono_domain_get ();
        
-       if (version == NULL) {
-               version = mono_get_runtime_info ()->framework_version;
-               moonlight = !strcmp (version, "2.1");
-       }
-       
        if (domain->socket_assembly == NULL) {
                MonoImage *socket_assembly;
 
-               if (moonlight) {
-                       socket_assembly = mono_image_loaded ("System.Net");
-                       if (!socket_assembly) {
-                               MonoAssembly *sa = mono_assembly_open ("System.Net.dll", NULL);
-                       
-                               if (!sa) {
-                                       g_assert_not_reached ();
-                               } else {
-                                       socket_assembly = mono_assembly_get_image (sa);
-                               }
-                       }
-               } else {
-                       socket_assembly = mono_image_loaded ("System");
-                       if (!socket_assembly) {
-                               MonoAssembly *sa = mono_assembly_open ("System.dll", NULL);
-                       
-                               if (!sa) {
-                                       g_assert_not_reached ();
-                               } else {
-                                       socket_assembly = mono_assembly_get_image (sa);
-                               }
+               socket_assembly = mono_image_loaded ("System");
+               if (!socket_assembly) {
+                       MonoAssembly *sa = mono_assembly_open ("System.dll", NULL);
+               
+                       if (!sa) {
+                               g_assert_not_reached ();
+                       } else {
+                               socket_assembly = mono_assembly_get_image (sa);
                        }
                }
-
-               domain->socket_assembly = socket_assembly;
+               mono_atomic_store_release (&domain->socket_assembly, socket_assembly);
        }
        
        return domain->socket_assembly;
@@ -950,20 +930,11 @@ static MonoObject *create_object_from_sockaddr(struct sockaddr *saddr,
                g_assert (domain->sockaddr_data_field);
        }
 
-       /* Make sure there is space for the family and size bytes */
-#ifdef HAVE_SYS_UN_H
-       if (saddr->sa_family == AF_UNIX) {
-               /* sa_len includes the entire sockaddr size, so we don't need the
-                * N bytes (sizeof (unsigned short)) of the family. */
-               data=mono_array_new_cached(domain, mono_get_byte_class (), sa_size);
-       } else
-#endif
-       {
-               /* May be the +2 here is too conservative, as sa_len returns
-                * the length of the entire sockaddr_in/in6, including
-                * sizeof (unsigned short) of the family */
-               data=mono_array_new_cached(domain, mono_get_byte_class (), sa_size+2);
-       }
+       /* May be the +2 here is too conservative, as sa_len returns
+        * the length of the entire sockaddr_in/in6, including
+        * sizeof (unsigned short) of the family */
+       /* We can't really avoid the +2 as all code below depends on this size - INCLUDING unix domain sockets.*/
+       data=mono_array_new_cached(domain, mono_get_byte_class (), sa_size+2);
 
        /* The data buffer is laid out as follows:
         * bytes 0 and 1 are the address family