Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
try to port the gras simulation side to the new smx_network infrastructure (not yet...
[simgrid.git] / src / gras / Msg / gras_msg_listener.c
index e4930fc..c66c18a 100644 (file)
@@ -26,6 +26,14 @@ typedef struct s_gras_msg_listener_ {
   xbt_thread_t listener;
 } s_gras_msg_listener_t;
 
+static void do_close_socket(gras_socket_t sock) {
+  if (sock->plugin->socket_close)
+     (*sock->plugin->socket_close) (sock);
+   /* free the memory */
+   if (sock->peer_name)
+     free(sock->peer_name);
+   free(sock);
+}
 static void listener_function(void *p)
 {
   gras_msg_listener_t me = (gras_msg_listener_t) p;
@@ -56,12 +64,9 @@ static void listener_function(void *p)
     /* empty the list of sockets to trash */
     TRY {
       while (1) {
-        int sock;
+        gras_socket_t sock;
         xbt_queue_shift_timed(me->socks_to_close, &sock, 0);
-        if (tcp_close(sock) < 0) {
-          WARN3("error while closing tcp socket %d: %d (%s)\n",
-                sock, sock_errno, sock_errstr(sock_errno));
-        }
+        do_close_socket(sock);
       }
     }
     CATCH(e) {
@@ -103,28 +108,22 @@ gras_msg_listener_t gras_msg_listener_launch(xbt_queue_t msg_exchange)
 }
 
 #include "gras/Virtu/virtu_private.h"   /* procdata_t content */
-void gras_msg_listener_shutdown(gras_msg_listener_t l)
+void gras_msg_listener_shutdown()
 {
   gras_procdata_t *pd = gras_procdata_get();
   char kill = '0';
   DEBUG0("Listener quit");
 
-
   if (pd->listener)
     gras_msg_send(pd->listener->wakeup_sock_master_side, "_wakeup_listener",
-                  &kill);
+          &kill);
 
-  /* FIXME: thread_join is not implemented in SG (remove next conditional when fixed)
-   * But I guess it's not a big deal since we're terminating the thread mainly to
-   * make it free its OS locks on darwin.
-   * darwin is definitly different from the neat & nice SG world */
-  if (gras_if_RL())
-    xbt_thread_join(pd->listener->listener);
+  xbt_thread_join(pd->listener->listener);
 
   //  gras_socket_close(pd->listener->wakeup_sock_master_side); FIXME: uncommenting this leads to deadlock at terminaison
-  xbt_queue_free(&l->incomming_messages);
-  xbt_queue_free(&l->socks_to_close);
-  xbt_free(l);
+  xbt_queue_free(&pd->listener->incomming_messages);
+  xbt_queue_free(&pd->listener->socks_to_close);
+  xbt_free(pd->listener);
 }
 
 void gras_msg_listener_awake()
@@ -140,14 +139,14 @@ void gras_msg_listener_awake()
   }
 }
 
-void gras_msg_listener_close_socket(int sd)
+void gras_msg_listener_close_socket(gras_socket_t sock)
 {
   gras_procdata_t *pd = gras_procdata_get();
   if (pd->listener) {
-    xbt_queue_push(pd->listener->socks_to_close, &sd);
+    xbt_queue_push(pd->listener->socks_to_close, &sock);
     gras_msg_listener_awake();
   } else {
     /* do it myself */
-    tcp_close(sd);
+    do_close_socket(sock);
   }
 }