Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Current state. Does not work yet, but I'd prefer not to loose it ;)
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 6 Jul 2004 01:51:13 +0000 (01:51 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 6 Jul 2004 01:51:13 +0000 (01:51 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@178 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/gras/Transport/sg_transport.c
src/gras/Virtu/sg_process.c

index bf56bc5..917d8af 100644 (file)
@@ -30,24 +30,61 @@ gras_error_t
 gras_trp_select(double timeout, 
                gras_socket_t **dst) {
 
+  gras_error_t errcode;
   double startTime=gras_time();
   gras_procdata_t *pd=gras_procdata_get();
   gras_trp_sg_sock_data_t *sockdata;
+  gras_trp_plugin_t *trp;
+
+  gras_socket_t *sock_iter; /* iterating over all sockets */
+  int cursor;               /* iterating over all sockets */
 
   int r_pid, cpt;
-  m_process_t remote;
   gras_hostdata_t *remote_hd;
+
+  DEBUG1("select with timeout=%d",timeout);
   do {
     r_pid = MSG_task_probe_from((m_channel_t) pd->chan);
     if (r_pid >= 0) {
-      *dst = pd->sock;
-      sockdata = (*dst)->data;
+      /* Try to reuse an already openned socket to that expeditor */
+      gras_dynar_foreach(pd->sockets,cursor,sock_iter) {
+       DEBUG1("Consider %p as outgoing socket to expeditor",sock_iter);
+       sockdata = sock_iter->data;
+
+       if (sock_iter->raw || !sock_iter->outgoing)
+         continue;
+
+       if (sockdata->from_PID == r_pid) {
+         *dst=sock_iter;
+         return no_error;
+       }
+      }
+
+      /* Socket to expeditor not created yet */
+      DEBUG0("Create a socket to the expeditor");
+
+      TRY(gras_trp_plugin_get_by_name("sg",&trp));
+
+      TRY(gras_trp_socket_new(1,dst));
+      (*dst)->plugin   = trp;
+
+      (*dst)->incoming  = 1;
+      (*dst)->outgoing  = 1;
+      (*dst)->accepting = 0;
+      (*dst)->sd        = -1;
+
+      (*dst)->port      = -1;
+
+      if (!(sockdata = malloc(sizeof(gras_trp_sg_sock_data_t))))
+       RAISE_MALLOC;
 
-      remote = MSG_process_from_PID(r_pid);
       sockdata->from_PID = r_pid;
       sockdata->to_PID = MSG_process_self_PID();
-      sockdata->to_host = MSG_process_get_host(remote);
+      sockdata->to_host = MSG_process_get_host(MSG_process_from_PID(r_pid));
+      (*dst)->data = sockdata;
+
+      (*dst)->peer_port = -1;
+      (*dst)->peer_name = strdup(MSG_host_get_name(sockdata->to_host));
 
       remote_hd=(gras_hostdata_t *)MSG_host_get_data(sockdata->to_host);
       gras_assert0(remote_hd,"Run gras_process_init!!");
@@ -71,7 +108,7 @@ gras_trp_select(double timeout,
 
 }
 
-
+  
 /* dummy implementations of the functions used in RL mode */
 
 gras_error_t gras_trp_tcp_setup(gras_trp_plugin_t *plug) {
index a69254a..ec571ec 100644 (file)
@@ -61,10 +61,6 @@ gras_process_init() {
 
   hd->proc[ i ] = MSG_process_self_PID();
 
-  /* Connect a dummy socket to ourselves. It's returned by select() */
-  TRY(gras_socket_client(MSG_host_get_name(MSG_host_self()),
-                        pd->chan, &(pd->sock)));
-
   VERB2("Creating process '%s' (%d)",
           MSG_process_get_name(MSG_process_self()),
           MSG_process_self_PID());