Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 21 Jun 2004 17:54:53 +0000 (17:54 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 21 Jun 2004 17:54:53 +0000 (17:54 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@140 48e7efb5-ca39-0410-a469-dd3cf9ba447f

examples/ping/ping.c
src/gras/DataDesc/datadesc_private.h

index 286b074..b477365 100644 (file)
@@ -66,12 +66,12 @@ int server_cb_ping_handler(gras_socket_t        *expeditor,
                              
   gras_error_t errcode;
   msg_ping_t *msg=payload_data;
-  gras_msgtype_t *pong_t;
+  gras_msgtype_t *pong_t=NULL;
 
   server_data_t *g=(server_data_t*)gras_userdata_get();
 
   g->endcondition = 0;
-  INFO3("SERVER: >>>>>>>> Got message PING(%d) from %s:%d <<<<<<<<\n", 
+  INFO3("SERVER: >>>>>>>> Got message PING(%d) from %s:%d <<<<<<<<", 
        msg->dummy, 
        gras_socket_peer_name(expeditor),
        gras_socket_peer_port(expeditor));
@@ -80,7 +80,6 @@ int server_cb_ping_handler(gras_socket_t        *expeditor,
   TRY(gras_msgtype_by_name("pong",&pong_t));
   errcode = gras_msg_send(expeditor, pong_t, payload_data);
 
-  free(payload_data);
   if (errcode != no_error) {
     ERROR1("SERVER: Unable answer with PONG: %s\n", gras_error_name(errcode));
     gras_socket_close(&(g->sock));
@@ -88,7 +87,7 @@ int server_cb_ping_handler(gras_socket_t        *expeditor,
   }
 
   free(msg);
-  INFO0("SERVER: >>>>>>>> Answed with PONG(4321) <<<<<<<<\n");
+  INFO0("SERVER: >>>>>>>> Answed with PONG(4321) <<<<<<<<");
   g->endcondition = 1;
   return 1;
 }
@@ -96,7 +95,7 @@ int server_cb_ping_handler(gras_socket_t        *expeditor,
 int server (int argc,char *argv[]) {
   gras_error_t errcode;
   server_data_t *g=gras_userdata_new(server_data_t);  
-  gras_msgtype_t *ping_msg;
+  gras_msgtype_t *ping_msg=NULL;
 
   int port = 4000;
   
@@ -104,12 +103,15 @@ int server (int argc,char *argv[]) {
     port=atoi(argv[1]);
   }
 
+  INFO1("Launch server (port=%d)", port);
+
   if ((errcode=gras_socket_server(port,&(g->sock)))) { 
     CRITICAL1("Error %s encountered while opening the server socket",
              gras_error_name(errcode));
     return 1;
   }
 
+  TRYFAIL(register_messages());
   TRYFAIL(register_messages());
   TRYFAIL(gras_msgtype_by_name("ping",&ping_msg));
   TRYFAIL(gras_cb_register(ping_msg,&server_cb_ping_handler));
@@ -119,14 +121,15 @@ int server (int argc,char *argv[]) {
   g->endcondition=0;
 
   while (1) {
-    errcode = gras_msg_handle(60.0);
+    errcode = gras_msg_handle(10.0);
     if (errcode != no_error && errcode != timeout_error) 
       return errcode;
     if (g->endcondition)
       break;
   }
-
-  gras_sleep(5,0);
+  
+  if (!gras_if_RL())
+    gras_sleep(5,0);
   INFO0("SERVER: Done.");
   gras_socket_close(&(g->sock));
   return no_error;
@@ -155,26 +158,30 @@ int client(int argc,char *argv[]) {
   const char *host = "127.0.0.1";
         int   port = 4000;
 
+  msg_ping_type = msg_pong_type = NULL;
+   
   if (argc == 3) {
     host=argv[1];
     port=atoi(argv[2]);
   } 
 
+  fprintf(stderr,"Launch client (server on %s:%d)",host,port);
+  if (!gras_if_RL())
+    gras_sleep(5,0); /* Wait for the server to be setup */
   if ((errcode=gras_socket_client(host,port,&(g->sock)))) {
-    fprintf(stderr,"Client: Unable to connect to the server. Got %s\n",
-           gras_error_name(errcode));
+    ERROR1("Client: Unable to connect to the server. Got %s",
+          gras_error_name(errcode));
     return 1;
   }
-  fprintf(stderr,"Client: Connected to %s:%d.\n",host,port);    
+  INFO2("Client: Connected to %s:%d.",host,port);    
 
 
   TRY(register_messages());
   TRY(gras_msgtype_by_name("ping",&msg_ping_type));
   TRY(gras_msgtype_by_name("pong",&msg_pong_type));
 
-  fprintf(stderr,
-         "Client: >>>>>>>> Connected to server which is on %s:%d <<<<<<<<\n", 
-         gras_socket_peer_name(g->sock),gras_socket_peer_port(g->sock));
+  INFO2("Client: >>>>>>>> Connected to server which is on %s:%d <<<<<<<<", 
+       gras_socket_peer_name(g->sock),gras_socket_peer_port(g->sock));
 
   msg_ping_data = malloc(sizeof(msg_ping_t));
   msg_ping_data->dummy = 1234;
@@ -185,29 +192,27 @@ int client(int argc,char *argv[]) {
     gras_socket_close(&(g->sock));
     return 1;
   }
-  fprintf(stderr,"Client: >>>>>>>> Message PING(%d) sent to %s:%d <<<<<<<<\n",
-         msg_ping_data->dummy,
-         gras_socket_peer_name(g->sock),gras_socket_peer_port(g->sock));
+  INFO3("Client: >>>>>>>> Message PING(%d) sent to %s:%d <<<<<<<<",
+       msg_ping_data->dummy,
+       gras_socket_peer_name(g->sock),gras_socket_peer_port(g->sock));
 
   msg_pong_data = NULL;
   if ((errcode=gras_msg_wait(6000,
                             msg_pong_type,&from,(void**)&msg_pong_data))) {
-    fprintf(stderr,
-         "Client: Why can't I get my PONG message like everyone else (%s)?\n",
-           gras_error_name(errcode));
+    ERROR1("Client: Why can't I get my PONG message like everyone else (%s)?",
+          gras_error_name(errcode));
     gras_socket_close(&(g->sock));
     return 1;
   }
 
-  fprintf(stderr,"Client: >>>>>>>> Got PONG(%d) got from %s:%d <<<<<<<<\n", 
-         msg_pong_data->dummy,
-         gras_socket_peer_name(from),gras_socket_peer_port(from));
+  INFO3("Client: >>>>>>>> Got PONG(%d) got from %s:%d <<<<<<<<", 
+       msg_pong_data->dummy,
+       gras_socket_peer_name(from),gras_socket_peer_port(from));
 
   free(msg_ping_data);  
   free(msg_pong_data);
 
-  gras_sleep(5,0);
   gras_socket_close(&(g->sock));
-  fprintf(stderr,"Client: Done.\n");
+  INFO0("Client: Done.");
   return 0;
 }
index 00cdf32..9066df4 100644 (file)
@@ -52,10 +52,10 @@ typedef struct {
   int sizeof_scalars[9]; /* char,short,int,long,long_long,
                            pdata,pfunc,
                            float,double */
-} gras_arch_sizes_t;
-
-extern const gras_arch_sizes_t gras_arch_sizes[gras_arch_count];
+} gras_arch_desc_t;
 
+extern const gras_arch_desc_t gras_arches[gras_arch_count];
+extern const char *gras_datadesc_cat_names[9];
 
 /**********************************************************/
 /* Actual definitions of the stuff in the type descriptor */
@@ -64,22 +64,24 @@ extern const gras_arch_sizes_t gras_arch_sizes[gras_arch_count];
 /**
  * e_gras_datadesc_type_category:
  *
- * Defines all possible type categories
+ * Defines all possible type categories
  */
 typedef enum e_gras_datadesc_type_category {
-        e_gras_datadesc_type_cat_undefined = 0,
-
-        e_gras_datadesc_type_cat_scalar = 1,
-        e_gras_datadesc_type_cat_struct = 2,
-        e_gras_datadesc_type_cat_union = 3,
-        e_gras_datadesc_type_cat_ref = 4,       /* ref to an uniq element */
-        e_gras_datadesc_type_cat_array = 5,
-        e_gras_datadesc_type_cat_ignored = 6,
+  
+  /* if you edit this, also fix gras_datadesc_cat_names in ddt_exchange.c */
 
-        e_gras_datadesc_type_cat_invalid = 7
+  e_gras_datadesc_type_cat_undefined = 0,
+  
+  e_gras_datadesc_type_cat_scalar = 1,
+  e_gras_datadesc_type_cat_struct = 2,
+  e_gras_datadesc_type_cat_union = 3,
+  e_gras_datadesc_type_cat_ref = 4,       /* ref to an uniq element */
+  e_gras_datadesc_type_cat_array = 5,
+  e_gras_datadesc_type_cat_ignored = 6,
+  
+  e_gras_datadesc_type_cat_invalid = 7
 } gras_datadesc_type_category_t;
 
-
 /*------------------------------------------------*/
 /* definitions of specific data for each category */
 /*------------------------------------------------*/
@@ -207,6 +209,8 @@ struct s_gras_datadesc_type {
   char                                *name;
   unsigned int                         name_len;
         
+  unsigned int                         refcounter;
+   
   /* payload */
   long int                             size[gras_arch_count];
   
@@ -230,9 +234,6 @@ gras_datadesc_declare_scalar(const char                       *name,
                             gras_datadesc_type_cb_void_t     cb,
                             gras_datadesc_type_t           **dst);
 
-/* Do not use it on a registered type ! */
-void gras_ddt_free(gras_datadesc_type_t **type);
-
 /****************************************************
  * Callback persistant state constructor/destructor *
  ****************************************************/
@@ -250,3 +251,4 @@ gras_dd_convert_elm(gras_datadesc_type_t *type,
                    void *src, void *dst);
 
 #endif /* GRAS_DATADESC_PRIVATE_H */
+