Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
- Bugfix: flush the socket on close only if there is some *output*.
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 4 Mar 2005 11:37:31 +0000 (11:37 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 4 Mar 2005 11:37:31 +0000 (11:37 +0000)
   - Bugfix: flush idempotent when there's nothing to send (don't send size=0)

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

src/gras/Transport/transport_plugin_buf.c

index 5294c51..bbfe9dd 100644 (file)
@@ -160,8 +160,15 @@ void gras_trp_buf_socket_close(gras_socket_t sock){
   gras_trp_bufdata_t *data=sock->bufdata;
 
   XBT_IN;
-  if (data->in.size || data->out.size)
+  if (data->in.size!=data->in.pos) {
+     WARN1("Socket closed, but %d bytes were unread",data->in.size - data->in.pos);
+  }
+   
+  if (data->out.size!=data->out.pos) {
+    DEBUG2("Flush the socket before closing (in=%d,out=%d)",data->in.size, data->out.size);
     gras_trp_buf_flush(sock);
+  }
+   
   if (data->in.data)
     free(data->in.data);
   if (data->out.data)
@@ -277,8 +284,13 @@ gras_trp_buf_flush(gras_socket_t sock) {
   gras_trp_bufdata_t *data=sock->bufdata;
 
   XBT_IN;
-  size = (int)htonl(data->out.size);
-  DEBUG1("Send the size (=%d)",data->out.size);
+  if (! (data->out.size-data->out.pos) ) {
+     DEBUG0("Nothing to flush");
+     return no_error;
+  }
+   
+  size = (int)htonl(data->out.size-data->out.pos);
+  DEBUG1("Send the size (=%d)",data->out.size-data->out.pos);
   TRY(super->chunk_send(sock,(char*) &size, 4));
 
   DEBUG1("Send the chunk (size=%d)",data->out.size);