Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
embeed the buffer size within the buffer itself on SG. That way, send are atomic...
[simgrid.git] / src / gras / Transport / transport_plugin_sg.c
index 9089717..7b0425d 100644 (file)
@@ -22,6 +22,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(trp_sg,transport,"SimGrid pseudo-transport");
 /***
  *** Prototypes 
  ***/
+hexa_print(unsigned char *data, int size);   /* in gras.c */
+
 /* retrieve the port record associated to a numerical port on an host */
 static xbt_error_t find_port(gras_hostdata_t *hd, int port,
                              gras_sg_portrec_t *hpd);
@@ -278,13 +280,24 @@ xbt_error_t gras_trp_sg_chunk_recv(gras_socket_t sock,
   DEBUG1("Got chuck %s",MSG_task_get_name(task));
 
   task_data = MSG_task_get_data(task);
-  if (task_data->size != size)
-    RAISE5(mismatch_error,
-          "Got %d bytes when %ld where expected (in %s->%s:%d)",
-          task_data->size, size,
-          MSG_host_get_name(sock_data->to_host),
-          MSG_host_get_name(MSG_host_self()), sock_data->to_chan);
-  memcpy(data,task_data->data,size);
+  if (size != -1) {    
+     if (task_data->size != size)
+       RAISE5(mismatch_error,
+             "Got %d bytes when %ld where expected (in %s->%s:%d)",
+             task_data->size, size,
+             MSG_host_get_name(sock_data->to_host),
+             MSG_host_get_name(MSG_host_self()), sock_data->to_chan);
+     memcpy(data,task_data->data,size);
+  } else {
+     /* damn, the size is embeeded at the begining of the chunk */
+     int netsize;
+     
+     memcpy((char*)&netsize,task_data->data,4);
+     netsize = (int)ntohl(netsize);
+     DEBUG1("netsize embeeded = %d",netsize);
+
+     memcpy(data,task_data->data,netsize+4);
+  }
   free(task_data->data);
   free(task_data);