Author: gonzalo
Date: 2005-04-28 19:48:39 -0400 (Thu, 28 Apr 2005)
New Revision: 43756

Modified:
   trunk/mono/mono/io-layer/ChangeLog
   trunk/mono/mono/io-layer/handles-private.h
   trunk/mono/mono/io-layer/handles.c
   trunk/mono/mono/io-layer/sockets.c
Log:
2005-04-28 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>

        * handles.c:
        * handles-private.h: added _wapi_handle_forecch that loops through all
        the handles and call a callback function when a handle of the given
        type is found.

        * sockets.c: no need to keep open sockets in an array, as we have them 
        in the handles structure.

        Fixes bug #74755.



Modified: trunk/mono/mono/io-layer/ChangeLog
===================================================================
--- trunk/mono/mono/io-layer/ChangeLog  2005-04-28 23:41:34 UTC (rev 43755)
+++ trunk/mono/mono/io-layer/ChangeLog  2005-04-28 23:48:39 UTC (rev 43756)
@@ -1,3 +1,15 @@
+2005-04-28 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+       * handles.c:
+       * handles-private.h: added _wapi_handle_forecch that loops through all
+       the handles and call a callback function when a handle of the given
+       type is found.
+
+       * sockets.c: no need to keep open sockets in an array, as we have them 
+       in the handles structure.
+
+       Fixes bug #74755.
+
 2005-04-28  Dick Porter  <[EMAIL PROTECTED]>
 
        * processes.c: Cope with handles that are only around for as long

Modified: trunk/mono/mono/io-layer/handles-private.h
===================================================================
--- trunk/mono/mono/io-layer/handles-private.h  2005-04-28 23:41:34 UTC (rev 
43755)
+++ trunk/mono/mono/io-layer/handles-private.h  2005-04-28 23:48:39 UTC (rev 
43756)
@@ -92,6 +92,9 @@
                                      int fd);
 extern void _wapi_handle_dump (void);
 extern void _wapi_handle_update_refs (void);
+extern void _wapi_handle_foreach (WapiHandleType type,
+                                       gboolean (*on_each)(gpointer test, 
gpointer user),
+                                       gpointer user_data);
 
 /* This is OK to use for atomic writes of individual struct members, as they
  * are independent

Modified: trunk/mono/mono/io-layer/handles.c
===================================================================
--- trunk/mono/mono/io-layer/handles.c  2005-04-28 23:41:34 UTC (rev 43755)
+++ trunk/mono/mono/io-layer/handles.c  2005-04-28 23:48:39 UTC (rev 43756)
@@ -662,6 +662,38 @@
        return (TRUE);
 }
 
+void
+_wapi_handle_foreach (WapiHandleType type,
+                       gboolean (*on_each)(gpointer test, gpointer user),
+                       gpointer user_data)
+{
+       struct _WapiHandleUnshared *handle_data = NULL;
+       gpointer ret = NULL;
+       guint32 i, k;
+       int thr_ret;
+
+       pthread_cleanup_push ((void(*)(void *))mono_mutex_unlock_in_cleanup,
+                             (void *)&scan_mutex);
+       thr_ret = mono_mutex_lock (&scan_mutex);
+       g_assert (thr_ret == 0);
+
+       for (i = SLOT_INDEX (0); _wapi_private_handles [i] != NULL; i++) {
+               for (k = SLOT_OFFSET (0); k < _WAPI_HANDLE_INITIAL_COUNT; k++) {
+                       handle_data = &_wapi_private_handles [i][k];
+               
+                       if (handle_data->type == type) {
+                               ret = GUINT_TO_POINTER (i * 
_WAPI_HANDLE_INITIAL_COUNT + k);
+                               if (on_each (ret, user_data) == TRUE)
+                                       break;
+                       }
+               }
+       }
+
+       thr_ret = mono_mutex_unlock (&scan_mutex);
+       g_assert (thr_ret == 0);
+       pthread_cleanup_pop (0);
+}
+
 /* This might list some shared handles twice if they are already
  * opened by this process, and the check function returns FALSE the
  * first time.  Shared handles that are created during the search are

Modified: trunk/mono/mono/io-layer/sockets.c
===================================================================
--- trunk/mono/mono/io-layer/sockets.c  2005-04-28 23:41:34 UTC (rev 43755)
+++ trunk/mono/mono/io-layer/sockets.c  2005-04-28 23:48:39 UTC (rev 43756)
@@ -37,7 +37,6 @@
 #undef DEBUG
 
 static guint32 startup_count=0;
-static GPtrArray *sockets=NULL;
 static pthread_key_t error_key;
 static mono_once_t error_key_once=MONO_ONCE_INIT;
 
@@ -70,8 +69,6 @@
                return;
        }
 
-       g_ptr_array_remove_fast (sockets, handle);
-
        do {
                ret = close (GPOINTER_TO_UINT(handle));
        } while (ret == -1 && errno == EINTR &&
@@ -98,10 +95,6 @@
                return(WSAVERNOTSUPPORTED);
        }
 
-       if (startup_count == 0) {
-               sockets = g_ptr_array_new();
-       }
-       
        startup_count++;
 
        /* I've no idea what is the minor version of the spec I read */
@@ -120,6 +113,13 @@
        return(0);
 }
 
+static gboolean
+cleanup_close (gpointer handle, gpointer data)
+{
+       _wapi_handle_ops_close (handle, NULL);
+       return TRUE;
+}
+
 int WSACleanup(void)
 {
        guint32 i;
@@ -132,18 +132,8 @@
                /* Do nothing */
                return(0);
        }
-       
-       /* Close down all sockets */
-       for (i = 0; i < sockets->len; i++) {
-               gpointer handle;
 
-               handle = g_ptr_array_index (sockets, i);
-               _wapi_handle_ops_close (handle, NULL);
-       }
-
-       g_ptr_array_free (sockets, FALSE);
-       sockets = NULL;
-       
+       _wapi_handle_foreach (WAPI_HANDLE_SOCKET, cleanup_close, NULL);
        return(0);
 }
 
@@ -241,8 +231,6 @@
                return(INVALID_SOCKET);
        }
 
-       g_ptr_array_add (sockets, new_handle);
-       
 #ifdef DEBUG
        g_message ("%s: returning newly accepted socket handle %p with",
                   __func__, new_handle);
@@ -719,8 +707,6 @@
                return(INVALID_SOCKET);
        }
 
-       g_ptr_array_add (sockets, handle);
-
 #ifdef DEBUG
        g_message ("%s: returning socket handle %p", __func__, handle);
 #endif

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to