Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
implement refcount on sockets since they are somehow shared between sender and receiv...
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 25 Nov 2010 09:24:22 +0000 (09:24 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 25 Nov 2010 09:24:22 +0000 (09:24 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8647 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/gras/Msg/sg_msg.c
src/gras/Transport/transport.c
src/gras/Transport/transport_private.h

index fc1b66d..7f87f66 100644 (file)
@@ -47,7 +47,7 @@ gras_msg_t gras_msg_recv_any(void)
          rdv_client : sock_data->rdv_server, sock_data->comm_recv);
 
 
-    /* The following assert fails in some valid conditions, we need to
+    /* If the following assert fails in some valid conditions, we need to
      * change the code downward looking for the socket again.
      *
      * For now it relies on the facts (A) that sockets and comms are aligned
@@ -138,6 +138,7 @@ void gras_msg_send_ext(gras_socket_t sock,
 
   /*initialize gras message */
   msg = xbt_new(s_gras_msg_t, 1);
+  sock->refcount++;
   msg->expe = sock;
   msg->kind = kind;
   msg->type = msgtype;
index cefc3e9..e7c51e0 100644 (file)
@@ -162,6 +162,7 @@ void gras_trp_socket_new(int incoming, gras_socket_t * dst)
   sock->valid = 1;
   sock->moredata = 0;
 
+  sock->refcount = 1;
   sock->sd = -1;
 
   sock->data = NULL;
@@ -336,6 +337,9 @@ void gras_socket_close_voidp(void *sock)
 /** \brief Close socket */
 void gras_socket_close(gras_socket_t sock)
 {
+  if (--sock->refcount)
+    return;
+
   xbt_dynar_t sockets =
       ((gras_trp_procdata_t)
        gras_libdata_by_id(gras_trp_libdata_id))->sockets;
@@ -438,6 +442,7 @@ int gras_socket_peer_port(gras_socket_t sock)
 
 const char *gras_socket_peer_name(gras_socket_t sock)
 {
+  xbt_assert(sock->plugin);
   return (*sock->plugin->peer_name)(sock);
 }
 
index ad0f55d..c74efd5 100644 (file)
@@ -70,6 +70,8 @@ typedef struct s_gras_socket {
   int recvd:1;                  /* true if the recvd_val field contains one byte of the stream (that we peek'ed to check the socket validity) */
   char recvd_val;               /* what we peeked from the socket, if any */
 
+  int refcount;                 /* refcounting on shared sockets */
+
   unsigned long int buf_size;   /* what to say to the OS. 
                                    Field here to remember it when accepting */