Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Tell explicitly gcc that hexa_print returns void
[simgrid.git] / src / gras / Transport / transport_plugin_sg.c
index 2472072..41351dc 100644 (file)
@@ -11,7 +11,7 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include <msg.h>
+#include "msg/msg.h"
 
 #include "transport_private.h"
 #include "gras/Virtu/virtu_sg.h"
@@ -22,6 +22,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(trp_sg,transport,"SimGrid pseudo-transport");
 /***
  *** Prototypes 
  ***/
+void 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);
@@ -153,7 +155,7 @@ xbt_error_t gras_trp_sg_socket_server(gras_trp_plugin_t *self,
   xbt_error_t errcode;
 
   gras_hostdata_t *hd=(gras_hostdata_t *)MSG_host_get_data(MSG_host_self());
-  gras_procdata_t *pd=gras_procdata_get();
+  gras_trp_procdata_t pd=(gras_trp_procdata_t)gras_libdata_get("gras_trp");
   gras_sg_portrec_t pr;
   gras_trp_sg_sock_data_t *data;
   
@@ -204,11 +206,13 @@ void gras_trp_sg_socket_close(gras_socket_t sock){
   
   gras_sg_portrec_t pr;
 
+  XBT_IN1(" (sock=%p)",sock);
+   
   if (!sock) return;
   xbt_assert0(hd,"Please run gras_process_init on each process");
 
   if (sock->data)
-    xbt_free(sock->data);
+    free(sock->data);
 
   if (sock->incoming) {
     /* server mode socket. Un register it from 'OS' tables */
@@ -216,11 +220,13 @@ void gras_trp_sg_socket_close(gras_socket_t sock){
       DEBUG2("Check pr %d of %lu", cpt, xbt_dynar_length(hd->ports));
       if (pr.port == sock->port) {
        xbt_dynar_cursor_rm(hd->ports, &cpt);
-       return;
+       XBT_OUT;
+        return;
       }
     }
     WARN0("socket_close called on an unknown socket");
   }
+  XBT_OUT;
 }
 
 typedef struct {
@@ -259,7 +265,7 @@ xbt_error_t gras_trp_sg_chunk_send(gras_socket_t sock,
 xbt_error_t gras_trp_sg_chunk_recv(gras_socket_t sock,
                                    char *data,
                                    long int size){
-  gras_procdata_t *pd=gras_procdata_get();
+  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;
@@ -271,17 +277,29 @@ xbt_error_t gras_trp_sg_chunk_recv(gras_socket_t sock,
         MSG_host_get_name(MSG_host_self()), sock_data->to_chan, size);
   if (MSG_task_get(&task, (sock->raw ? pd->rawChan : pd->chan)) != MSG_OK)
     RAISE0(unknown_error,"Error in MSG_task_get()");
+  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);
-  xbt_free(task_data->data);
-  xbt_free(task_data);
+  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);
 
   if (MSG_task_destroy(task) != MSG_OK)
     RAISE0(unknown_error,"Error in MSG_task_destroy()");
@@ -302,7 +320,7 @@ xbt_error_t gras_socket_raw_exchange(gras_socket_t peer,
   char name[256];
   gras_trp_sg_sock_data_t *sock_data = (gras_trp_sg_sock_data_t *)peer->data;
   
-  gras_procdata_t *pd=gras_procdata_get();
+  gras_trp_procdata_t pd=(gras_trp_procdata_t)gras_libdata_get("gras_trp");
   double startTime;
   
   startTime=gras_os_time(); /* used only in sender mode */