Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Integrate Bruno's work on SIMIX onto main stream. Tests are broken, but it looks...
[simgrid.git] / src / gras_simix / Transport / gras_simix_transport.c
index 134b418..f2db951 100644 (file)
@@ -15,7 +15,7 @@ int gras_opt_trp_nomoredata_on_close=0;
 #include "xbt/ex.h"
 #include "xbt/peer.h"
 #include "portable.h"
-#include "gras/Transport/transport_private.h"
+#include "gras_simix/Transport/gras_simix_transport_private.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_trp,gras,"Conveying bytes over the network");
 XBT_LOG_NEW_SUBCATEGORY(gras_trp_meas,gras_trp,"Conveying bytes over the network without formating for perf measurements");
@@ -97,10 +97,10 @@ void gras_trp_init(void){
 
 void
 gras_trp_exit(void){
-  xbt_dynar_t sockets = ((gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id))->sockets;
-  gras_socket_t sock_iter;
-  int cursor;
-
+  //xbt_dynar_t sockets = ((gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id))->sockets;
+  //gras_socket_t sock_iter;
+  //int cursor;
+       DEBUG1("gras_trp valor %d",_gras_trp_started);
    if (_gras_trp_started == 0) {
       return;
    }
@@ -115,13 +115,15 @@ gras_trp_exit(void){
        }
 #endif
 
-      /* Close all the sockets */
+      /* Close all the sockets, moved to process_close */
+                       /*
+                       DEBUG1("sockets pointer %p",sockets);
       xbt_dynar_foreach(sockets,cursor,sock_iter) {
        VERB1("Closing the socket %p left open on exit. Maybe a socket leak?",
              sock_iter);
        gras_socket_close(sock_iter);
       }
-      
+      */
       /* Delete the plugins */
       xbt_dict_free(&_gras_trp_plugins);
    }
@@ -360,20 +362,22 @@ void gras_socket_close(gras_socket_t sock) {
   }
    
   /* FIXME: Issue an event when the socket is closed */
+       DEBUG1("sockets pointer before %p",sockets);
   if (sock) {
-    xbt_dynar_foreach(sockets,cursor,sock_iter) {
-      if (sock == sock_iter) {
-       xbt_dynar_cursor_rm(sockets,&cursor);
-       if (sock->plugin->socket_close) 
-         (* sock->plugin->socket_close)(sock);
-
-       /* free the memory */
-       if (sock->peer_name)
-         free(sock->peer_name);
-       free(sock);
-       XBT_OUT;
-       return;
-      }
+               xbt_dynar_foreach(sockets,cursor,sock_iter) {
+                       if (sock == sock_iter) {
+                               DEBUG2("remove sock cursor %d dize %lu\n",cursor,xbt_dynar_length(sockets));
+                               xbt_dynar_cursor_rm(sockets,&cursor);
+                               if (sock->plugin->socket_close) 
+                                       (* sock->plugin->socket_close)(sock);
+
+                               /* free the memory */
+                               if (sock->peer_name)
+                                       free(sock->peer_name);
+                               free(sock);
+                               XBT_OUT;
+                               return;
+                       }
     }
     WARN1("Ignoring request to free an unknown socket (%p). Execution stack:",sock);
     xbt_backtrace_display();
@@ -573,7 +577,7 @@ static void *gras_trp_procdata_new() {
    
    res->name = xbt_strdup("gras_trp");
    res->name_len = 0;
-   res->sockets   = xbt_dynar_new(sizeof(gras_socket_t*), NULL);
+   res->sockets = xbt_dynar_new(sizeof(gras_socket_t*), NULL);
    res->myport = 0;
    
    return (void*)res;