Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
- Do not close sockets closed on other side: user may keep references to them.
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sun, 9 Jul 2006 23:28:08 +0000 (23:28 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sun, 9 Jul 2006 23:28:08 +0000 (23:28 +0000)
  Instead, mark them as invalid and ignore them.
- Do raise a timeout when a poll fails (timeout=0, but no message here)
- New function: gras_trp_socketset_dump to display the content of the socket
  set.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2508 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/gras/Transport/rl_transport.c
src/gras/Transport/transport.c
src/gras/Transport/transport_interface.h
src/gras/Transport/transport_private.h

index 5b6b6ec..6d65d78 100644 (file)
@@ -70,6 +70,9 @@ gras_socket_t gras_trp_select(double timeout) {
     FD_ZERO(&FDS);
     max_fds = -1;
     xbt_dynar_foreach(sockets,cursor,sock_iter) {
     FD_ZERO(&FDS);
     max_fds = -1;
     xbt_dynar_foreach(sockets,cursor,sock_iter) {
+      if (!sock_iter->valid)
+        continue;
+       
       if (sock_iter->incoming) {
        DEBUG1("Considering socket %d for select",sock_iter->sd);
 #ifndef HAVE_WINSOCK_H
       if (sock_iter->incoming) {
        DEBUG1("Considering socket %d for select",sock_iter->sd);
 #ifndef HAVE_WINSOCK_H
@@ -144,7 +147,7 @@ gras_socket_t gras_trp_select(double timeout) {
       continue;         /* this was a timeout */
     }
 
       continue;         /* this was a timeout */
     }
 
-    xbt_dynar_foreach(sockets,cursor,sock_iter) { 
+    xbt_dynar_foreach(sockets,cursor,sock_iter) {
        if(!FD_ISSET(sock_iter->sd, &FDS)) { /* this socket is not ready */
        continue;
        }
        if(!FD_ISSET(sock_iter->sd, &FDS)) { /* this socket is not ready */
        continue;
        }
@@ -175,8 +178,7 @@ gras_socket_t gras_trp_select(double timeout) {
         } else if (recvd == 0) {
           /* Connection reset (=closed) by peer. */
           DEBUG1("Connection %d reset by peer", sock_iter->sd);
         } else if (recvd == 0) {
           /* Connection reset (=closed) by peer. */
           DEBUG1("Connection %d reset by peer", sock_iter->sd);
-          gras_socket_close(sock_iter); 
-          cursor--; 
+          sock_iter->valid=0; /* don't close it. User may keep references to it */
         } else { 
           /* Got a suited socket ! */
           XBT_OUT;
         } else { 
           /* Got a suited socket ! */
           XBT_OUT;
@@ -197,8 +199,9 @@ gras_socket_t gras_trp_select(double timeout) {
 
   }
 
 
   }
 
-  XBT_OUT;
-  return NULL;
+  /* No socket found. Maybe we had timeout=0 and nothing to do */
+  DEBUG0("TIMEOUT");
+  THROW0(timeout_error,0,"Timeout");
 }
 
 void gras_trp_sg_setup(gras_trp_plugin_t plug) {
 }
 
 void gras_trp_sg_setup(gras_trp_plugin_t plug) {
index 623884d..a4ca069 100644 (file)
@@ -150,7 +150,7 @@ void gras_trp_socket_new(int incoming,
 
   gras_socket_t sock=xbt_new0(s_gras_socket_t,1);
 
 
   gras_socket_t sock=xbt_new0(s_gras_socket_t,1);
 
-  DEBUG1("Create a new socket (%p)", (void*)sock);
+  VERB1("Create a new socket (%p)", (void*)sock);
 
   sock->plugin = NULL;
 
 
   sock->plugin = NULL;
 
@@ -159,6 +159,7 @@ void gras_trp_socket_new(int incoming,
   sock->accepting = incoming ? 1:0;
   sock->meas = 0;
   sock->recv_ok = 1;
   sock->accepting = incoming ? 1:0;
   sock->meas = 0;
   sock->recv_ok = 1;
+  sock->valid = 1;
 
   sock->sd     = -1;
   sock->port      = -1;
 
   sock->sd     = -1;
   sock->port      = -1;
@@ -342,6 +343,7 @@ void gras_socket_close(gras_socket_t sock) {
   int cursor;
 
   XBT_IN;
   int cursor;
 
   XBT_IN;
+  VERB1("Close %p",sock);
   /* FIXME: Issue an event when the socket is closed */
   if (sock) {
     xbt_dynar_foreach(sockets,cursor,sock_iter) {
   /* FIXME: Issue an event when the socket is closed */
   if (sock) {
     xbt_dynar_foreach(sockets,cursor,sock_iter) {
@@ -556,11 +558,27 @@ static void *gras_trp_procdata_new() {
  * Freeing procdata for this module
  */
 static void gras_trp_procdata_free(void *data) {
  * Freeing procdata for this module
  */
 static void gras_trp_procdata_free(void *data) {
-   gras_trp_procdata_t res = (gras_trp_procdata_t)data;
-   
-   xbt_dynar_free(&( res->sockets ));
-   free(res->name);
-   free(res);
+  gras_trp_procdata_t res = (gras_trp_procdata_t)data;
+  
+  xbt_dynar_free(&( res->sockets ));
+  free(res->name);
+  free(res);
+}
+
+void gras_trp_socketset_dump(const char *name) {
+  gras_trp_procdata_t procdata = 
+    (gras_trp_procdata_t)gras_libdata_by_id(gras_trp_libdata_id);
+
+  int it;
+  gras_socket_t s;
+
+  INFO1("** Dump the socket set %s",name);
+  xbt_dynar_foreach(procdata->sockets, it, s) {
+    INFO4("  %p -> %s:%d %s",
+         s,gras_socket_peer_name(s),gras_socket_peer_port(s),
+         s->valid?"(valid)":"(peer dead)");
+  }
+  INFO1("** End of socket set %s",name);
 }
 
 /*
 }
 
 /*
index 0cad561..abbc09f 100644 (file)
@@ -102,4 +102,7 @@ typedef struct {
    
 } s_gras_trp_procdata_t,*gras_trp_procdata_t;
 
    
 } s_gras_trp_procdata_t,*gras_trp_procdata_t;
 
+/* Display the content of our socket set (debugging purpose) */
+void gras_trp_socketset_dump(const char *name);
+
 #endif /* GRAS_TRP_INTERFACE_H */
 #endif /* GRAS_TRP_INTERFACE_H */
index 88357d6..a2d50dc 100644 (file)
@@ -41,6 +41,7 @@ typedef struct s_gras_socket  {
   int accepting :1; /* true if master incoming sock in tcp */
   int meas :1; /* true if this is an experiment socket instead of messaging */
   int recv_ok :1; /* true if it is valid to recv() on the socket (false if it is a file) */
   int accepting :1; /* true if master incoming sock in tcp */
   int meas :1; /* true if this is an experiment socket instead of messaging */
   int recv_ok :1; /* true if it is valid to recv() on the socket (false if it is a file) */
+  int valid :1; /* false if a select returned that the peer quitted, forcing us to "close" the socket */
 
   unsigned long int buf_size; /* what to say to the OS. field here to remember it when accepting */
    
 
   unsigned long int buf_size; /* what to say to the OS. field here to remember it when accepting */