Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Tweak gras_trp_*_recv() prototype. This is now (sock, char*data,int size, int bufsize...
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 5 Sep 2005 22:46:23 +0000 (22:46 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 5 Sep 2005 22:46:23 +0000 (22:46 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1694 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/gras/Transport/transport_interface.h
src/gras/Transport/transport_plugin_buf.c
src/gras/Transport/transport_plugin_file.c
src/gras/Transport/transport_plugin_sg.c
src/gras/Transport/transport_plugin_tcp.c

index e1e8548..249db65 100644 (file)
@@ -58,7 +58,8 @@ struct gras_trp_plugin_ {
                     unsigned long int size);
   void (*chunk_recv)(gras_socket_t sd,
                     char *data,
                     unsigned long int size);
   void (*chunk_recv)(gras_socket_t sd,
                     char *data,
-                    unsigned long int size);
+                    unsigned long int size,
+                    unsigned long int bufsize);
 
   /* flush has to make sure that the pending communications are achieved */
   void (*flush)(gras_socket_t sd);
 
   /* flush has to make sure that the pending communications are achieved */
   void (*flush)(gras_socket_t sd);
index ed64bc3..0dc830d 100644 (file)
@@ -41,7 +41,8 @@ void gras_trp_buf_chunk_send(gras_socket_t sd,
 
 void gras_trp_buf_chunk_recv(gras_socket_t sd,
                             char *data,
 
 void gras_trp_buf_chunk_recv(gras_socket_t sd,
                             char *data,
-                            unsigned long int size);
+                            unsigned long int size,
+                            unsigned long int bufsize);
 void gras_trp_buf_flush(gras_socket_t sock);
 
 
 void gras_trp_buf_flush(gras_socket_t sock);
 
 
@@ -221,7 +222,8 @@ gras_trp_buf_chunk_send(gras_socket_t sock,
 void
 gras_trp_buf_chunk_recv(gras_socket_t sock,
                        char *chunk,
 void
 gras_trp_buf_chunk_recv(gras_socket_t sock,
                        char *chunk,
-                       unsigned long int size) {
+                       unsigned long int size,
+                       unsigned long int bufsize) {
 
   xbt_ex_t e;
   gras_trp_bufdata_t *data=sock->bufdata;
 
   xbt_ex_t e;
   gras_trp_bufdata_t *data=sock->bufdata;
@@ -242,7 +244,7 @@ gras_trp_buf_chunk_recv(gras_socket_t sock,
       if (gras_if_RL()) {
         DEBUG0("Recv the size");
         TRY {
       if (gras_if_RL()) {
         DEBUG0("Recv the size");
         TRY {
-          _buf_super->chunk_recv(sock,(char*)&nextsize, 4);
+          _buf_super->chunk_recv(sock,(char*)&nextsize, 4,4);
         } CATCH(e) {
           RETHROW3("Unable to get the chunk size on %p (peer = %s:%d): %s",
                    sock,gras_socket_peer_name(sock),gras_socket_peer_port(sock));
         } CATCH(e) {
           RETHROW3("Unable to get the chunk size on %p (peer = %s:%d): %s",
                    sock,gras_socket_peer_name(sock),gras_socket_peer_port(sock));
@@ -253,7 +255,7 @@ gras_trp_buf_chunk_recv(gras_socket_t sock,
         data->in.size = -1;
       }
        
         data->in.size = -1;
       }
        
-      _buf_super->chunk_recv(sock, data->in.data, data->in.size);
+      _buf_super->chunk_recv(sock, data->in.data, data->in.size, data->in.size);
        
       if (gras_if_RL()) {
         data->in.pos=0;
        
       if (gras_if_RL()) {
         data->in.pos=0;
index a85fa4b..7e7eae0 100644 (file)
@@ -25,7 +25,8 @@ void gras_trp_file_chunk_send(gras_socket_t sd,
 
 void gras_trp_file_chunk_recv(gras_socket_t sd,
                              char *data,
 
 void gras_trp_file_chunk_recv(gras_socket_t sd,
                              char *data,
-                             unsigned long int size);
+                             unsigned long int size,
+                             unsigned long int bufsize);
 
 
 /***
 
 
 /***
@@ -202,16 +203,18 @@ gras_trp_file_chunk_send(gras_socket_t sock,
 void
 gras_trp_file_chunk_recv(gras_socket_t sock,
                         char *data,
 void
 gras_trp_file_chunk_recv(gras_socket_t sock,
                         char *data,
-                        unsigned long int size) {
+                        unsigned long int size,
+                        unsigned long int bufsize) {
 
   xbt_assert0(sock, "Cannot recv on an NULL socket");
   xbt_assert0(sock->incoming, "Cannot recv on client file socket");
   xbt_assert0(size >= 0, "Cannot receive a negative amount of data");
 
   xbt_assert0(sock, "Cannot recv on an NULL socket");
   xbt_assert0(sock->incoming, "Cannot recv on client file socket");
   xbt_assert0(size >= 0, "Cannot receive a negative amount of data");
-  
+  xbt_assert0(bufsize>=size,"Not enough buffer size to receive that much data");
+
   while (size) {
     int status = 0;
     
   while (size) {
     int status = 0;
     
-    status = read(sock->sd, data, (long int)size);
+    status = read(sock->sd, data, (long int)bufsize);
     DEBUG3("read(%d, %p, %ld);", sock->sd, data, size);
     
     if (status == -1) {
     DEBUG3("read(%d, %p, %ld);", sock->sd, data, size);
     
     if (status == -1) {
@@ -221,8 +224,9 @@ gras_trp_file_chunk_recv(gras_socket_t sock,
     }
     
     if (status) {
     }
     
     if (status) {
-      size  -= status;
-      data  += status;
+      size    -= status;
+      bufsize -= status;
+      data    += status;
     } else {
       THROW0(system_error,0,"file descriptor closed");
     }
     } else {
       THROW0(system_error,0,"file descriptor closed");
     }
index e777b58..8c81ca2 100644 (file)
@@ -42,7 +42,8 @@ void gras_trp_sg_chunk_send(gras_socket_t sd,
 
 void gras_trp_sg_chunk_recv(gras_socket_t sd,
                            char *data,
 
 void gras_trp_sg_chunk_recv(gras_socket_t sd,
                            char *data,
-                           unsigned long int size);
+                           unsigned long int size,
+                           unsigned long int bufsize);
 
 /***
  *** Specific plugin part
 
 /***
  *** Specific plugin part
@@ -242,6 +243,8 @@ void gras_trp_sg_chunk_send(gras_socket_t sock,
   gras_trp_sg_sock_data_t *sock_data = (gras_trp_sg_sock_data_t *)sock->data;
   sg_task_data_t *task_data;
   
   gras_trp_sg_sock_data_t *sock_data = (gras_trp_sg_sock_data_t *)sock->data;
   sg_task_data_t *task_data;
   
+  xbt_assert0(sock->meas, "SG chunk exchange shouldn't be used on non-measurement sockets");
+
   sprintf(name,"Chunk[%d]",count++);
 
   task_data=xbt_new(sg_task_data_t,1);
   sprintf(name,"Chunk[%d]",count++);
 
   task_data=xbt_new(sg_task_data_t,1);
@@ -261,13 +264,15 @@ void gras_trp_sg_chunk_send(gras_socket_t sock,
 
 void gras_trp_sg_chunk_recv(gras_socket_t sock,
                            char *data,
 
 void gras_trp_sg_chunk_recv(gras_socket_t sock,
                            char *data,
-                           unsigned long int size){
+                           unsigned long int size,
+                           unsigned long int bufsize){
   gras_trp_procdata_t pd=(gras_trp_procdata_t)gras_libdata_get("gras_trp");
 
   m_task_t task=NULL;
   sg_task_data_t *task_data;
   gras_trp_sg_sock_data_t *sock_data = sock->data;
 
   gras_trp_procdata_t pd=(gras_trp_procdata_t)gras_libdata_get("gras_trp");
 
   m_task_t task=NULL;
   sg_task_data_t *task_data;
   gras_trp_sg_sock_data_t *sock_data = sock->data;
 
+  xbt_assert0(sock->meas, "SG chunk exchange shouldn't be used on non-measurement sockets");
   XBT_IN;
   DEBUG4("recv chunk on %s ->  %s:%d (size=%ld)",
         MSG_host_get_name(sock_data->to_host),
   XBT_IN;
   DEBUG4("recv chunk on %s ->  %s:%d (size=%ld)",
         MSG_host_get_name(sock_data->to_host),
index 51f44fa..21cdf35 100644 (file)
@@ -34,7 +34,8 @@ void gras_trp_tcp_chunk_send(gras_socket_t sd,
 
 void gras_trp_tcp_chunk_recv(gras_socket_t sd,
                             char *data,
 
 void gras_trp_tcp_chunk_recv(gras_socket_t sd,
                             char *data,
-                            unsigned long int size);
+                            unsigned long int size,
+                            unsigned long int bufsize);
 
 void gras_trp_tcp_exit(gras_trp_plugin_t plug);
 
 
 void gras_trp_tcp_exit(gras_trp_plugin_t plug);
 
@@ -328,17 +329,19 @@ gras_trp_tcp_chunk_send(gras_socket_t sock,
 void
 gras_trp_tcp_chunk_recv(gras_socket_t sock,
                        char *data,
 void
 gras_trp_tcp_chunk_recv(gras_socket_t sock,
                        char *data,
-                       unsigned long int size) {
+                       unsigned long int size,
+                       unsigned long int bufsize) {
 
   /* TCP sockets are in duplex mode, don't check direction */
   xbt_assert0(sock, "Cannot recv on an NULL socket");
   xbt_assert0(size >= 0, "Cannot receive a negative amount of data");
 
   /* TCP sockets are in duplex mode, don't check direction */
   xbt_assert0(sock, "Cannot recv on an NULL socket");
   xbt_assert0(size >= 0, "Cannot receive a negative amount of data");
+  xbt_assert0(bufsize>=size,"Not enough buffer size to receive that much data");
   
   while (size) {
     int status = 0;
     
     DEBUG3("read(%d, %p, %ld);", sock->sd, data, size);
   
   while (size) {
     int status = 0;
     
     DEBUG3("read(%d, %p, %ld);", sock->sd, data, size);
-    status = tcp_read(sock->sd, data, (size_t)size);
+    status = tcp_read(sock->sd, data, (size_t)bufsize);
     
     if (status < 0) {
       THROW4(system_error,0,"read(%d,%p,%d) failed: %s",
     
     if (status < 0) {
       THROW4(system_error,0,"read(%d,%p,%d) failed: %s",
@@ -347,12 +350,12 @@ gras_trp_tcp_chunk_recv(gras_socket_t sock,
     }
     
     if (status) {
     }
     
     if (status) {
-      size  -= status;
-      data  += status;
+      size    -= status;
+      bufsize -= status;
+      data    += status;
     } else {
     } else {
-      THROW3(system_error,0,
-            "file descriptor closed (nothing read(%d, %p, %ld) on the socket)",
-             sock->sd, data, size);
+      gras_socket_close(sock);
+      THROW0(system_error,0,"Socket closed by remote side");
     }
   }
 }
     }
   }
 }