Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
the ansi c declaration of variables are at the begining of block
authorcherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 13 Apr 2007 09:34:28 +0000 (09:34 +0000)
committercherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 13 Apr 2007 09:34:28 +0000 (09:34 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3409 48e7efb5-ca39-0410-a469-dd3cf9ba447f

examples/gras/p2p/can/can.c
examples/gras/p2p/can/can_tests.c

index 2cc62c0..7f5f0b5 100644 (file)
@@ -80,7 +80,7 @@ static int node_get_suc_handler(gras_msg_cb_ctx_t ctx,void *payload_data){
        get_suc_t *incoming=(get_suc_t*)payload_data;
        xbt_ex_t e; // the error variable used in TRY.. CATCH tokens.
        node_data_t *globals=(node_data_t*)gras_userdata_get();
        get_suc_t *incoming=(get_suc_t*)payload_data;
        xbt_ex_t e; // the error variable used in TRY.. CATCH tokens.
        node_data_t *globals=(node_data_t*)gras_userdata_get();
-
+       gras_socket_t temp_sock=NULL;
        INFO3("Received a get_successor message from %s for (%d;%d)",gras_socket_peer_name(expeditor),incoming->xId,incoming->yId);
        //INFO4("My area is [%d;%d;%d;%d]",globals->x1,globals->x2,globals->y1,globals->y2);
        if(incoming->xId<globals->x1) // test if the message must be forwarded to a neighbour.
        INFO3("Received a get_successor message from %s for (%d;%d)",gras_socket_peer_name(expeditor),incoming->xId,incoming->yId);
        //INFO4("My area is [%d;%d;%d;%d]",globals->x1,globals->x2,globals->y1,globals->y2);
        if(incoming->xId<globals->x1) // test if the message must be forwarded to a neighbour.
@@ -178,7 +178,7 @@ static int node_get_suc_handler(gras_msg_cb_ctx_t ctx,void *payload_data){
                }
                if(validate==1){ // the area for the new node has been defined, then send theses informations to the new node.
                        INFO2("Sending environment informations to node %s:%d",incoming->host,incoming->port);
                }
                if(validate==1){ // the area for the new node has been defined, then send theses informations to the new node.
                        INFO2("Sending environment informations to node %s:%d",incoming->host,incoming->port);
-                       gras_socket_t temp_sock=NULL;   
+
                        TRY{
                                temp_sock=gras_socket_client(incoming->host,incoming->port);
                        }CATCH(e){
                        TRY{
                                temp_sock=gras_socket_client(incoming->host,incoming->port);
                        }CATCH(e){
@@ -213,6 +213,12 @@ static int node_get_suc_handler(gras_msg_cb_ctx_t ctx,void *payload_data){
 int node(int argc,char **argv){
        node_data_t *globals=NULL;
        xbt_ex_t e; // the error variable used in TRY.. CATCH tokens.
 int node(int argc,char **argv){
        node_data_t *globals=NULL;
        xbt_ex_t e; // the error variable used in TRY.. CATCH tokens.
+       gras_socket_t temp_sock=NULL;
+
+       rep_suc_t rep_suc_msg;
+
+       get_suc_t get_suc_msg; // building the "get_suc" message.
+       gras_socket_t temp_sock2=NULL;
 
        INFO0("Starting");
 
 
        INFO0("Starting");
 
@@ -238,14 +244,14 @@ int node(int argc,char **argv){
                globals->y2=1000;
        }else{ // asking for an area.
                INFO1("Contacting %s so as to request for an area",argv[4]);
                globals->y2=1000;
        }else{ // asking for an area.
                INFO1("Contacting %s so as to request for an area",argv[4]);
-               gras_socket_t temp_sock=NULL;
+
                TRY{
                        temp_sock=gras_socket_client(argv[4],atoi(argv[5]));
                }CATCH(e){
                        RETHROW0("Unable to connect known host to request for an area!: %s");
                }
 
                TRY{
                        temp_sock=gras_socket_client(argv[4],atoi(argv[5]));
                }CATCH(e){
                        RETHROW0("Unable to connect known host to request for an area!: %s");
                }
 
-               get_suc_t get_suc_msg; // building the "get_suc" message.
+
                get_suc_msg.xId=globals->xId;
                get_suc_msg.yId=globals->yId;
                strcpy(get_suc_msg.host,globals->host);
                get_suc_msg.xId=globals->xId;
                get_suc_msg.yId=globals->yId;
                strcpy(get_suc_msg.host,globals->host);
@@ -258,8 +264,8 @@ int node(int argc,char **argv){
                }
                gras_socket_close(temp_sock);
 
                }
                gras_socket_close(temp_sock);
 
-               rep_suc_t rep_suc_msg;
-               gras_socket_t temp_sock2=NULL;
+
+
                TRY{ // waiting for a reply.
                        INFO0("Waiting for reply!");
                        gras_msg_wait(6000,"can_rep_suc",&temp_sock2,&rep_suc_msg);
                TRY{ // waiting for a reply.
                        INFO0("Waiting for reply!");
                        gras_msg_wait(6000,"can_rep_suc",&temp_sock2,&rep_suc_msg);
index 8fdbdef..52c5ad7 100644 (file)
@@ -24,11 +24,13 @@ typedef struct s_nuke nuke_t;
 // the function that start the **** War of the Nodes ****
 int start_war(int argc,char **argv);
 int start_war(int argc,char **argv){
 // the function that start the **** War of the Nodes ****
 int start_war(int argc,char **argv);
 int start_war(int argc,char **argv){
+       gras_socket_t temp_sock=NULL;
+       nuke_t nuke_msg;
+  xbt_ex_t e; // the error variable used in TRY.. CATCH tokens.
   //return 0; // in order to inhibit the War of the Nodes 
   gras_init(&argc,argv);
   gras_os_sleep((15-gras_os_getpid())*20+200); // wait a bit.
   //return 0; // in order to inhibit the War of the Nodes 
   gras_init(&argc,argv);
   gras_os_sleep((15-gras_os_getpid())*20+200); // wait a bit.
-  gras_socket_t temp_sock=NULL;
-  xbt_ex_t e; // the error variable used in TRY.. CATCH tokens.
+
        
   TRY{ // contacting the bad guy that will launch the War.
     temp_sock=gras_socket_client(gras_os_myname(),atoi(argv[1]));
        
   TRY{ // contacting the bad guy that will launch the War.
     temp_sock=gras_socket_client(gras_os_myname(),atoi(argv[1]));
@@ -36,7 +38,7 @@ int start_war(int argc,char **argv){
     RETHROW0("Unable to connect known host so as to declare WAR!: %s");
   }
   
     RETHROW0("Unable to connect known host so as to declare WAR!: %s");
   }
   
-  nuke_t nuke_msg;
+
   nuke_msg.xId=-1;
   nuke_msg.yId=-1;
   nuke_msg.version=atoi(argv[2]); 
   nuke_msg.xId=-1;
   nuke_msg.yId=-1;
   nuke_msg.version=atoi(argv[2]); 
@@ -57,6 +59,8 @@ int start_war(int argc,char **argv){
 // the function thaht send the nuke "msg" on (xId;yId), if it's not on me :p.
 static int send_nuke(nuke_t *msg, int xId, int yId){
   node_data_t *globals=(node_data_t*)gras_userdata_get();
 // the function thaht send the nuke "msg" on (xId;yId), if it's not on me :p.
 static int send_nuke(nuke_t *msg, int xId, int yId){
   node_data_t *globals=(node_data_t*)gras_userdata_get();
+  gras_socket_t temp_sock=NULL;
+   xbt_ex_t e; // the error variable used in TRY.. CATCH tokens.
 
   if(xId>=globals->x1 && xId<=globals->x2 && yId>=globals->y1 && yId<=globals->y2){
     INFO0("Nuclear launch missed");
 
   if(xId>=globals->x1 && xId<=globals->x2 && yId>=globals->y1 && yId<=globals->y2){
     INFO0("Nuclear launch missed");
@@ -82,8 +86,8 @@ static int send_nuke(nuke_t *msg, int xId, int yId){
     msg->xId=xId;
     msg->yId=yId;
 
     msg->xId=xId;
     msg->yId=yId;
 
-    gras_socket_t temp_sock=NULL;
-    xbt_ex_t e; // the error variable used in TRY.. CATCH tokens.
+
+
     TRY{ // sending the nuke.
       temp_sock=gras_socket_client(host,port);
     }CATCH(e){
     TRY{ // sending the nuke.
       temp_sock=gras_socket_client(host,port);
     }CATCH(e){
@@ -106,13 +110,18 @@ static int node_nuke_handler(gras_msg_cb_ctx_t ctx,void *payload_data){
   gras_socket_t expeditor=gras_msg_cb_ctx_from(ctx);
   nuke_t *incoming=(nuke_t*)payload_data;
   node_data_t *globals=(node_data_t*)gras_userdata_get();
   gras_socket_t expeditor=gras_msg_cb_ctx_from(ctx);
   nuke_t *incoming=(nuke_t*)payload_data;
   node_data_t *globals=(node_data_t*)gras_userdata_get();
+  
+       int x;
+       int y;
+       nuke_t nuke_msg; // writing my name one the nuke.
+        gras_socket_t temp_sock=NULL;
+        xbt_ex_t e; // the error variable used in TRY.. CATCH tokens.
+       
 
   if(incoming->xId==-1){ // i must start the War
     INFO2("%s:%d declare the WAR!!!!!!!!!!!!!!!!!",globals->host,globals->port);
     srand((unsigned int)time((time_t *)NULL));
 
 
   if(incoming->xId==-1){ // i must start the War
     INFO2("%s:%d declare the WAR!!!!!!!!!!!!!!!!!",globals->host,globals->port);
     srand((unsigned int)time((time_t *)NULL));
 
-    int x;
-    int y;
     do{
       x=(int)(1000.0*rand()/(RAND_MAX+1.0));
       y=(int)(1000.0*rand()/(RAND_MAX+1.0));
     do{
       x=(int)(1000.0*rand()/(RAND_MAX+1.0));
       y=(int)(1000.0*rand()/(RAND_MAX+1.0));
@@ -138,13 +147,12 @@ static int node_nuke_handler(gras_msg_cb_ctx_t ctx,void *payload_data){
       int x4=(int)(1000.0*rand()/(RAND_MAX+1.0));
       int y4=(int)(1000.0*rand()/(RAND_MAX+1.0));*/
       
       int x4=(int)(1000.0*rand()/(RAND_MAX+1.0));
       int y4=(int)(1000.0*rand()/(RAND_MAX+1.0));*/
       
-      nuke_t nuke_msg; // writing my name one the nuke.
-      nuke_msg.version=incoming->version; 
+
+         nuke_msg.version=incoming->version;
       strcpy(nuke_msg.host,globals->host);
       nuke_msg.port=globals->port;
       
       strcpy(nuke_msg.host,globals->host);
       nuke_msg.port=globals->port;
       
-      int x;
-      int y;
+         
       do{
        x=(int)(1000.0*rand()/(RAND_MAX+1.0));
        y=(int)(1000.0*rand()/(RAND_MAX+1.0));
       do{
        x=(int)(1000.0*rand()/(RAND_MAX+1.0));
        y=(int)(1000.0*rand()/(RAND_MAX+1.0));
@@ -169,9 +177,9 @@ static int node_nuke_handler(gras_msg_cb_ctx_t ctx,void *payload_data){
       strcpy(host,globals->north_host);
       port=globals->north_port;}
     
       strcpy(host,globals->north_host);
       port=globals->north_port;}
     
-    gras_socket_t temp_sock=NULL;
-    xbt_ex_t e; // the error variable used in TRY.. CATCH tokens.
-    TRY{
+
+
+       TRY{
       temp_sock=gras_socket_client(host,port);
     }CATCH(e){
       RETHROW0("Unable to connect the nuke!: %s");
       temp_sock=gras_socket_client(host,port);
     }CATCH(e){
       RETHROW0("Unable to connect the nuke!: %s");
@@ -185,7 +193,7 @@ static int node_nuke_handler(gras_msg_cb_ctx_t ctx,void *payload_data){
     gras_socket_close(temp_sock);
   }
   gras_socket_close(expeditor); // spare.
     gras_socket_close(temp_sock);
   }
   gras_socket_close(expeditor); // spare.
-  xbt_ex_t e; // the error variable used in TRY.. CATCH tokens.
+
   TRY{
     gras_msg_handle(10000.0); // wait a bit, in case of..
   }CATCH(e){
   TRY{
     gras_msg_handle(10000.0); // wait a bit, in case of..
   }CATCH(e){