X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/3d0d626e19a7b79320e7d922c9c1dcf122076cea..9b5ba1582444ecd1bc7904b2aa0bb71fcabffc5e:/examples/ping/ping.c diff --git a/examples/ping/ping.c b/examples/ping/ping.c index 800df8b20d..460e30400e 100644 --- a/examples/ping/ping.c +++ b/examples/ping/ping.c @@ -2,11 +2,10 @@ /* ping - ping/pong demo of GRAS features */ -/* Authors: Martin Quinson */ -/* Copyright (C) 2003 the OURAGAN project. */ +/* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved. */ /* 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. */ + * under the terms of the license (GNU LGPL) which comes with this package. */ #include #include @@ -14,7 +13,7 @@ #include "gras.h" -GRAS_LOG_NEW_DEFAULT_CATEGORY(Ping,"Messages specific to this example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(Ping,"Messages specific to this example"); /* ********************************************************************** * Comon code @@ -40,20 +39,20 @@ void register_messages(void) { /* Global private data */ typedef struct { - gras_socket_t *sock; + gras_socket_t sock; int endcondition; } server_data_t; /* Function prototypes */ -int server_cb_ping_handler(gras_socket_t *expeditor, - void *payload_data); +int server_cb_ping_handler(gras_socket_t expeditor, + void *payload_data); int server (int argc,char *argv[]); -int server_cb_ping_handler(gras_socket_t *expeditor, - void *payload_data) { +int server_cb_ping_handler(gras_socket_t expeditor, + void *payload_data) { - gras_error_t errcode; + xbt_error_t errcode; int msg=*(int*)payload_data; gras_msgtype_t *pong_t=NULL; @@ -69,7 +68,7 @@ int server_cb_ping_handler(gras_socket_t *expeditor, errcode = gras_msg_send(expeditor, gras_msgtype_by_name("pong"), &msg); if (errcode != no_error) { - ERROR1("SERVER: Unable answer with PONG: %s\n", gras_error_name(errcode)); + ERROR1("SERVER: Unable answer with PONG: %s\n", xbt_error_name(errcode)); gras_socket_close(g->sock); return 1; } @@ -81,13 +80,13 @@ int server_cb_ping_handler(gras_socket_t *expeditor, } int server (int argc,char *argv[]) { - gras_error_t errcode; + xbt_error_t errcode; server_data_t *g; gras_msgtype_t *ping_msg=NULL; int port = 4000; - gras_init(&argc,argv); + gras_init(&argc,argv, NULL); g=gras_userdata_new(server_data_t); if (argc == 2) { @@ -98,7 +97,7 @@ int server (int argc,char *argv[]) { if ((errcode=gras_socket_server(port,&(g->sock)))) { CRITICAL1("Error %s encountered while opening the server socket", - gras_error_name(errcode)); + xbt_error_name(errcode)); return 1; } @@ -116,7 +115,8 @@ int server (int argc,char *argv[]) { if (g->endcondition) if (!gras_if_RL()) - gras_os_sleep(5,0); + gras_os_sleep(1,0); + gras_socket_close(g->sock); free(g); gras_exit(); @@ -130,23 +130,23 @@ int server (int argc,char *argv[]) { /* Global private data */ typedef struct { - gras_socket_t *sock; + gras_socket_t sock; } client_data_t; /* Function prototypes */ int client (int argc,char *argv[]); int client(int argc,char *argv[]) { - gras_error_t errcode; + xbt_error_t errcode; client_data_t *g; - gras_socket_t *from; + gras_socket_t from; int ping, pong; const char *host = "127.0.0.1"; int port = 4000; - gras_init(&argc, argv); + gras_init(&argc, argv, NULL); g=gras_userdata_new(client_data_t); if (argc == 3) { @@ -155,10 +155,10 @@ int client(int argc,char *argv[]) { } INFO2("Launch client (server on %s:%d)",host,port); - gras_os_sleep(5,0); /* Wait for the server to be setup */ + gras_os_sleep(1,0); /* Wait for the server startup */ if ((errcode=gras_socket_client(host,port,&(g->sock)))) { ERROR1("Client: Unable to connect to the server. Got %s", - gras_error_name(errcode)); + xbt_error_name(errcode)); return 1; } INFO2("Client: Connected to %s:%d.",host,port); @@ -173,7 +173,7 @@ int client(int argc,char *argv[]) { errcode = gras_msg_send(g->sock, gras_msgtype_by_name("ping"), &ping); if (errcode != no_error) { fprintf(stderr, "Client: Unable send PING to server (%s)\n", - gras_error_name(errcode)); + xbt_error_name(errcode)); gras_socket_close(g->sock); return 1; } @@ -184,7 +184,7 @@ int client(int argc,char *argv[]) { if ((errcode=gras_msg_wait(6000,gras_msgtype_by_name("pong"), &from,&pong))) { ERROR1("Client: Why can't I get my PONG message like everyone else (%s)?", - gras_error_name(errcode)); + xbt_error_name(errcode)); gras_socket_close(g->sock); return 1; }