gras_msgtype_declare("hello", NULL);
mysock = gras_socket_server(12345);
- gras_msg_wait(60, gras_msgtype_by_name("hello"), &toclient, NULL /* no payload */);
+ gras_msg_wait(60, "hello", &toclient, NULL /* no payload */);
fprintf(stderr,"Cool, we received the message from %s:%d.\n",
gras_socket_peer_name(toclient), gras_socket_peer_port(toclient));
gras_os_sleep(1.5); /* sleep 1 second and half */
toserver = gras_socket_client("Jacquelin", 12345);
- gras_msg_send(toserver,gras_msgtype_by_name("hello"), NULL);
+ gras_msg_send(toserver,"hello", NULL);
fprintf(stderr,"That's it, we sent the data to the server\n");
gras_exit();
gras_msgtype_declare("hello", NULL);
mysock = gras_socket_server(atoi(argv[1]));
- gras_msg_wait(60, gras_msgtype_by_name("hello"), &toclient, NULL /* no payload */);
+ gras_msg_wait(60, "hello", &toclient, NULL /* no payload */);
fprintf(stderr,"Cool, we received the message from %s:%d.\n",
gras_socket_peer_name(toclient), gras_socket_peer_port(toclient));
gras_os_sleep(1.5); /* sleep 1 second and half */
toserver = gras_socket_client(argv[1], atoi(argv[2]));
- gras_msg_send(toserver,gras_msgtype_by_name("hello"), NULL);
+ gras_msg_send(toserver,"hello", NULL);
fprintf(stderr,"That's it, we sent the data to the server on %s\n", gras_socket_peer_name(toserver));
gras_exit();
fprintf(stderr,"Cool, we received the message from %s:%d.\n",
gras_socket_peer_name(client), gras_socket_peer_port(client));
- return 1;
+ return 0;
} /* end_of_callback */
int server(int argc, char *argv[]) {
gras_msgtype_declare("hello", NULL);
mysock = gras_socket_server(atoi(argv[1]));
- gras_cb_register(gras_msgtype_by_name("hello"),&server_hello_cb);
+ gras_cb_register("hello",&server_hello_cb);
gras_msg_handle(60);
gras_exit();
gras_os_sleep(1.5); /* sleep 1 second and half */
toserver = gras_socket_client(argv[1], atoi(argv[2]));
- gras_msg_send(toserver,gras_msgtype_by_name("hello"), NULL);
+ gras_msg_send(toserver,"hello", NULL);
fprintf(stderr,"That's it, we sent the data to the server on %s\n", gras_socket_peer_name(toserver));
gras_exit();
globals->killed = 1;
- return 1;
+ return 0;
} /* end_of_kill_callback */
int server_hello_cb(gras_msg_cb_ctx_t ctx, void *payload) {
fprintf(stderr,"Cool, we received the message from %s:%d.\n",
gras_socket_peer_name(client), gras_socket_peer_port(client));
- return 1;
+ return 0;
} /* end_of_hello_callback */
int server(int argc, char *argv[]) {
gras_msgtype_declare("kill", NULL);
mysock = gras_socket_server(atoi(argv[1]));
- gras_cb_register(gras_msgtype_by_name("hello"),&server_hello_cb);
- gras_cb_register(gras_msgtype_by_name("kill"),&server_kill_cb);
+ gras_cb_register("hello",&server_hello_cb);
+ gras_cb_register("kill",&server_kill_cb);
while (!globals->killed) {
gras_msg_handle(-1); /* blocking */
gras_os_sleep(1.5); /* sleep 1 second and half */
toserver = gras_socket_client(argv[1], atoi(argv[2]));
- gras_msg_send(toserver,gras_msgtype_by_name("hello"), NULL);
+ gras_msg_send(toserver,"hello", NULL);
fprintf(stderr,"we sent the data to the server on %s. Let's do it again for fun\n", gras_socket_peer_name(toserver));
- gras_msg_send(toserver,gras_msgtype_by_name("hello"), NULL);
+ gras_msg_send(toserver,"hello", NULL);
fprintf(stderr,"Ok. Enough. Have a rest, and then kill the server\n");
gras_os_sleep(5); /* sleep 1 second and half */
- gras_msg_send(toserver,gras_msgtype_by_name("kill"), NULL);
+ gras_msg_send(toserver,"kill", NULL);
gras_exit();
return 0;
globals->killed = 1;
- return 1;
+ return 0;
} /* end_of_kill_callback */
int server_hello_cb(gras_msg_cb_ctx_t ctx, void *payload) {
INFO2("Cool, we received the message from %s:%d.",
gras_socket_peer_name(client), gras_socket_peer_port(client));
- return 1;
+ return 0;
} /* end_of_hello_callback */
int server(int argc, char *argv[]) {
gras_msgtype_declare("kill", NULL);
mysock = gras_socket_server(atoi(argv[1]));
- gras_cb_register(gras_msgtype_by_name("hello"),&server_hello_cb);
- gras_cb_register(gras_msgtype_by_name("kill"),&server_kill_cb);
+ gras_cb_register("hello",&server_hello_cb);
+ gras_cb_register("kill",&server_kill_cb);
while (!globals->killed) {
gras_msg_handle(-1); /* blocking */
gras_os_sleep(1.5); /* sleep 1 second and half */
toserver = gras_socket_client(argv[1], atoi(argv[2]));
- gras_msg_send(toserver,gras_msgtype_by_name("hello"), NULL);
+ gras_msg_send(toserver,"hello", NULL);
INFO1("we sent the data to the server on %s. Let's do it again for fun", gras_socket_peer_name(toserver));
- gras_msg_send(toserver,gras_msgtype_by_name("hello"), NULL);
+ gras_msg_send(toserver,"hello", NULL);
INFO0("Ok. Enough. Have a rest, and then kill the server");
gras_os_sleep(5); /* sleep 1 second and half */
- gras_msg_send(toserver,gras_msgtype_by_name("kill"), NULL);
+ gras_msg_send(toserver,"kill", NULL);
gras_exit();
return 0;
globals->killed = 1;
- return 1;
+ return 0;
} /* end_of_kill_callback */
int server_hello_cb(gras_msg_cb_ctx_t ctx, void *payload) {
INFO2("Cool, we received the message from %s:%d.",
gras_socket_peer_name(client), gras_socket_peer_port(client));
- return 1;
+ return 0;
} /* end_of_hello_callback */
int server(int argc, char *argv[]) {
gras_msgtype_declare("kill", NULL);
mysock = gras_socket_server(atoi(argv[1]));
- gras_cb_register(gras_msgtype_by_name("hello"),&server_hello_cb);
- gras_cb_register(gras_msgtype_by_name("kill"),&server_kill_cb);
+ gras_cb_register("hello",&server_hello_cb);
+ gras_cb_register("kill",&server_kill_cb);
while (!globals->killed) {
gras_msg_handle(60);
void client_do_hello(void) {
client_data_t *globals=(client_data_t*)gras_userdata_get();
- gras_msg_send(globals->toserver,gras_msgtype_by_name("hello"), NULL);
+ gras_msg_send(globals->toserver,"hello", NULL);
INFO0("Hello sent to server");
} /* end_of_client_do_hello */
void client_do_stop(void) {
client_data_t *globals=(client_data_t*)gras_userdata_get();
- gras_msg_send(globals->toserver,gras_msgtype_by_name("kill"), NULL);
+ gras_msg_send(globals->toserver,"kill", NULL);
INFO0("Kill sent to server");
gras_timer_cancel_repeat(0.5,client_do_hello);
globals->killed = 1;
- return 1;
+ return 0;
} /* end_of_kill_callback */
int server(int argc, char *argv[]) {
globals->killed=0;
gras_msgtype_declare("kill", NULL);
- gras_cb_register(gras_msgtype_by_name("kill"),&server_kill_cb);
+ gras_cb_register("kill",&server_kill_cb);
if (argc>1 && !strcmp(argv[1],"--cheat")) {
mysock = gras_socket_server(9999);
for (port=3000, found=0; port<3010 && !found; port++) {
TRY {
toserver = gras_socket_client(argv[1], port);
- gras_msg_send(toserver,gras_msgtype_by_name("kill"), NULL);
+ gras_msg_send(toserver,"kill", NULL);
gras_socket_close(toserver);
found = 1;
INFO1("Yeah! I found the server on %d! It's eradicated by now.",port);
globals->killed = 1;
- return 1;
+ return 0;
} /* end_of_kill_callback */
int server_hello_cb(gras_msg_cb_ctx_t ctx, void *payload) {
gras_socket_peer_name(client), gras_socket_peer_port(client),
msg);
- return 1;
+ return 0;
} /* end_of_hello_callback */
void message_declaration(void) {
message_declaration();
mysock = gras_socket_server(atoi(argv[1]));
- gras_cb_register(gras_msgtype_by_name("hello"),&server_hello_cb);
- gras_cb_register(gras_msgtype_by_name("kill"),&server_kill_cb);
+ gras_cb_register("hello",&server_hello_cb);
+ gras_cb_register("kill",&server_kill_cb);
while (!globals->killed) {
gras_msg_handle(-1); /* blocking */
toserver = gras_socket_client(argv[1], atoi(argv[2]));
char *hello_payload="Nice to meet you";
- gras_msg_send(toserver,gras_msgtype_by_name("hello"), &hello_payload);
+ gras_msg_send(toserver,"hello", &hello_payload);
INFO1("we sent the hello to the server on %s.", gras_socket_peer_name(toserver));
double kill_payload=0.5;
- gras_msg_send(toserver,gras_msgtype_by_name("kill"), &kill_payload);
+ gras_msg_send(toserver,"kill", &kill_payload);
INFO0("Gave the server more 0.5 second to live");
gras_exit();
globals->done = 1;
INFO0("Server done");
- return 1;
+ return 0;
} /* end_of_done_callback */
void message_declaration(void) {
gras_msg_rpcreturn(60,ctx,&result);
free(result);
- return 1;
+ return 0;
} /* end_of_convert_callback */
int server_convert_a2i_cb(gras_msg_cb_ctx_t ctx, void *payload) {
THROW2(arg_error,0,"Error while converting %s: this does not seem to be a valid number (problem at '%s')",string,p);
gras_msg_rpcreturn(60,ctx,&result);
- return 1;
+ return 0;
} /* end_of_convert_callback */
message_declaration();
mysock = gras_socket_server(atoi(argv[1]));
- gras_cb_register(gras_msgtype_by_name("convert a2i"),&server_convert_a2i_cb);
- gras_cb_register(gras_msgtype_by_name("convert i2a"),&server_convert_i2a_cb);
- gras_cb_register(gras_msgtype_by_name("done"),&server_done_cb);
+ gras_cb_register("convert a2i",&server_convert_a2i_cb);
+ gras_cb_register("convert i2a",&server_convert_i2a_cb);
+ gras_cb_register("done",&server_done_cb);
while (!globals->done) {
gras_msg_handle(-1); /* blocking */
long long_to_convert=4321;
char *string_result;
INFO1("Ask to convert %ld", long_to_convert);
- gras_msg_rpccall(toserver, 60, gras_msgtype_by_name("convert i2a"), &long_to_convert, &string_result);
+ gras_msg_rpccall(toserver, 60, "convert i2a", &long_to_convert, &string_result);
INFO2("The server says that %ld is equal to \"%s\".", long_to_convert, string_result);
free(string_result);
char *string_to_convert="1234";
long long_result;
INFO1("Ask to convert %s", string_to_convert);
- gras_msg_rpccall(toserver, 60, gras_msgtype_by_name("convert a2i"), &string_to_convert, &long_result);
+ gras_msg_rpccall(toserver, 60, "convert a2i", &string_to_convert, &long_result);
INFO2("The server says that \"%s\" is equal to %d.", string_to_convert, long_result);
xbt_ex_t e;
string_to_convert = "azerty";
TRY {
- gras_msg_rpccall(toserver, 60, gras_msgtype_by_name("convert a2i"), &string_to_convert, &long_result);
+ gras_msg_rpccall(toserver, 60, "convert a2i", &string_to_convert, &long_result);
} CATCH(e) {
INFO1("The server refuses to convert %s. Here is the received exception:",string_to_convert);
xbt_ex_display(&e);
INFO0("Again, previous exception was excepted");
}
- gras_msg_send(toserver,gras_msgtype_by_name("done"), NULL);
+ gras_msg_send(toserver,"done", NULL);
INFO0("Stopped the server");
gras_exit();
} else {
globals->process_in_CS = 1;
INFO2("grant %s:%d since nobody wanted it",gras_socket_peer_name(s),gras_socket_peer_port(s));
- gras_msg_send(s, gras_msgtype_by_name("grant"), NULL);
+ gras_msg_send(s, "grant", NULL);
}
- return 1;
+ return 0;
} /* end_of_request_callback */
int server_release_cb(gras_msg_cb_ctx_t ctx, void *payload) {
xbt_dynar_pop(globals->waiting_queue, &s);
INFO2("grant %s:%d since token released",gras_socket_peer_name(s),gras_socket_peer_port(s));
- gras_msg_send(s, gras_msgtype_by_name("grant"), NULL);
+ gras_msg_send(s, "grant", NULL);
} else {
globals->process_in_CS = 0;
}
- return 1;
+ return 0;
} /* end_of_release_callback */
int server(int argc, char *argv[]) {
globals->waiting_queue=xbt_dynar_new( sizeof(gras_socket_t), NULL /* not closing sockets */);
message_declaration();
- gras_cb_register(gras_msgtype_by_name("request"),&server_request_cb);
- gras_cb_register(gras_msgtype_by_name("release"),&server_release_cb);
+ gras_cb_register("request",&server_request_cb);
+ gras_cb_register("release",&server_release_cb);
for (i=0; i<20; i++) /* 5 requests of each process, 2 processes, 2 messages per request */
gras_msg_handle(-1);
} /* end_of_server */
void lock(gras_socket_t toserver) {
- gras_msg_send(toserver,gras_msgtype_by_name("request"),NULL);
- gras_msg_wait(-1, gras_msgtype_by_name("grant"),NULL,NULL);
+ gras_msg_send(toserver,"request",NULL);
+ gras_msg_wait(-1, "grant",NULL,NULL);
INFO0("Granted by server");
} /* end_of_lock */
void unlock(gras_socket_t toserver) {
INFO0("Release the token");
- gras_msg_send(toserver,gras_msgtype_by_name("release"),NULL);
+ gras_msg_send(toserver,"release",NULL);
} /* end_of_unlock */
int client(int argc, char *argv[]) {
gras_msg_send on the sender side, and \ref gras_msg_wait on the receiver side.
\ref gras_msg_send expects 3 arguments: the socket on which to send the
-message, the message type, and a pointer to the actual content of the
-message. The simplest way to retrive a message type from its name is to use
-\ref gras_msgtype_by_name. Since we don't have any payload, this becomes:
+message, the message type (described by its name), and a pointer to the actual content of the
+message. Since we don't have any payload, this becomes:
\dontinclude 02-simple.c
\skip msg_send
arguments of relative types <tt>gras_msg_cb_ctx_t ctx</tt> and <tt>void
*</tt>. The first one is a working context we should pass to GRAS when
speaking about the message we are handling while the second is the payload.
-The callbackreturns an integer indicating whether we managed to deal with
-the message. I admit that this semantic is a bit troublesome, it should be 0
-if we managed to deal properly with the message to mimic "main()" semantic.
-That's historical, but I may change this in the future (no worry, I'll add
-backward compatibility solutions). Here is the actual code of our callback:
+The callback returns an integer being its error code, just like the "main()"
+function. Here is the actual code of our callback:
\dontinclude 04-callback.c
\skip gras_msg_cb_ctx_t
There is one last thing you should know about callbacks: you can stack them,
ie attach several callbacks to the same message. GRAS will pass it to the
-lastly attached first, and if the return value is 0, it will pass it also to
-the next one, and so on. I'm not sure there is any sensible use of this
-feature, but it's possible ;)
+lastly attached first, and if the returned error code is not 0, it will pass
+it also to the next one, and so on. I'm not sure there is any sensible use
+of this feature, but it's possible ;)
Go to \ref GRAS_tut_tour_globals
*/
*/
+ and the this example do use structures as payload,
+ so we have to declare it to GRAS. Hopefully, this can be done easily by enclosing
+ the structure declaration within a \ref GRAS_DEFINE_TYPE macro call. It will then copy this
+ declaration into an hidden string variable, which can be automatically parsed at
+ run time. Of course, the declaration is also copied unmodified by this macro, so that it
+ gets parsed by the compiler also.
+
+ There is some semantic that GRAS cannot guess alone and you need to <i>annotate</i>
+ your declaration to add some. For example, the ctn pointer can be a reference to an
+ object or a whole array (in which case you also has to specify its size). This is done
+ with the GRAS_ANNOTE call. It is removed from the text passed to the compiler, but it helps
+ GRAS getting some information about the semantic of your data. Here, it says that \a ctn is an
+ array, which size is the result of the operation \a rows * \a cols (with \a rows and \a cols
+ being the other fields of the structure).
+
+ Please note that this annotation mechanism is not as robust and cool as this example seems to
+ imply. If you want to use it yourself, you'd better use the exact right syntax, which is
+ detailed in the \ref GRAS_dd section.
+
+ \skip GRAS_DEFINE_TYPE
+ \until matrix_t
+
+
+
#define COLS 16
#define MAX_ROUTESET 10
#define MAX_LEAFSET COLS
mallocated in your callback (including the data you returned to the caller:
GRAS made a copy of it during the call to gras_msg_rpcreturn()).
-The callback is expected to return 1 if ok, as detailed in
+The callback is expected to return 0 if ok, as detailed in
\ref GRAS_tut_tour_message_recaping_rpc_aside1.
\subsection GRAS_tut_tour_message_recaping_rpc4 4. Attaching callbacks to the messages
\subsection GRAS_tut_tour_message_recaping_rpc_aside1 Aside: stacking callbacks
-The callback is expected to return 1 if it consumed the message properly.
-This semantic may be troublesome since it really differs from the one used
-in the main() function, but this allows to build callback stacks. It is
-perfectly valid to register several callbacks to a given message. When a
-message arrives, it is passed to the firstly-registered callback. If the
-callback returns 1 (or any other "true" value), it means that it consumed
-the message, which is discarded. If the callback returns 0, the message is
-passed to the next callback of the stack, and so on. At the end, if no
-callback returned 1, an error message is generated.
+The callback is expected to return 0 if everything went well, which is the
+same semantic than the "main()" function. You can also build stacks of
+callbacks. It is perfectly valid to register several callbacks to a given
+message. When a message arrives, it is passed to the firstly-registered
+callback. If the callback returns 0, it means that it consumed the message,
+which is discarded. If the callback returns 1 (or any other "true" value),
+the message is passed to the next callback of the stack, and so on. At the
+end, if no callback returned 0, an exception is raised.
This mecanism can for example be used to introduce dupplication and replay.
You add a callback simply in charge of storing the message in a database,
-and since it returns 0, the message is then passed to the "real" callback.
+and since it returns 1, the message is then passed to the "real" callback.
To be perfectly honest, I never had use of this functionnality myself, but I
feel it could be useful in some cases...
static void kill_buddy(char *name,int port){
gras_socket_t sock=gras_socket_client(name,port);
- gras_msg_send(sock,gras_msgtype_by_name("kill"),NULL);
+ gras_msg_send(sock,"kill",NULL);
gras_socket_close(sock);
}
static void kill_buddy_dynar(void *b) {
todo);
while (todo>0) {
gras_msg_wait(60 /* wait up to one minute */,
- gras_msgtype_by_name("data"),
+ "data",
&expeditor,
&data);
todo--;
xbt_dynar_foreach(peers,i,h) {
peer = gras_socket_client(h->name,h->port);
- gras_msg_send(peer,gras_msgtype_by_name("data"),&data);
+ gras_msg_send(peer,"data",&data);
INFO2(" Sent Data from %s to %s",
gras_os_myname(),h->name);
gras_socket_close(peer);
xbt_matrix_dump(request[1],"C:sent1",0,xbt_matrix_dump_display_double);
*/
- gras_msg_send(toserver, gras_msgtype_by_name("request"), &request);
+ gras_msg_send(toserver, "request", &request);
xbt_matrix_free(request[0]);
gras_socket_peer_name(toserver),gras_socket_peer_port(toserver));
/* 8. Wait for the answer from the server, and deal with issues */
- gras_msg_wait(6000,gras_msgtype_by_name("answer"),&from,&answer);
+ gras_msg_wait(6000,"answer",&from,&answer);
/*
xbt_matrix_dump(answer,"C:answer",0,xbt_matrix_dump_display_double);
matrix_type=gras_datadesc_matrix(gras_datadesc_by_name("double"),
NULL);
request_type=gras_datadesc_array_fixed("s_matrix_t(double)[2]",matrix_type,2);
- // gras_datadesc_by_name("xbt_matrix_t(double)"),2);
- // request_type=gras_datadesc_ref("matrix_t(double)[2]",request_type);
gras_msgtype_declare("answer", matrix_type);
gras_msgtype_declare("request", request_type);
result = xbt_matrix_double_new_mult(request[0], request[1]);
/* 3. Send it back as payload of a pong message to the expeditor */
- gras_msg_send(expeditor, gras_msgtype_by_name("answer"), &result);
+ gras_msg_send(expeditor, "answer", &result);
/* 4. Cleanups */
xbt_matrix_free(request[0]);
xbt_matrix_free(result);
gras_socket_close(expeditor);
- return 1;
+ return 0;
} /* end_of_server_cb_request_handler */
int server (int argc,char *argv[]) {
/* 5. Send the token as payload of a stoken message to the successor */
TRY {
- gras_msg_send(globals->tosuccessor,
- gras_msgtype_by_name("stoken"), &msg);
+ gras_msg_send(globals->tosuccessor, "stoken", &msg);
/* 6. Deal with errors */
} CATCH(e) {
}
/* 9. Tell GRAS that we consummed this message */
- return 1;
+ return 0;
} /* end_of_node_cb_stoken_handler */
int node (int argc,char *argv[]) {
token, host, peerport);
TRY {
- gras_msg_send(globals->tosuccessor,
- gras_msgtype_by_name("stoken"), &token);
+ gras_msg_send(globals->tosuccessor, "stoken", &token);
} CATCH(e) {
RETHROW0("Unable to send the freshly created token: %s");
}
RETHROW0("Unable to connect!: %s");
}
TRY{
- gras_msg_send(temp_sock,gras_msgtype_by_name("can_get_suc"),&msg);
+ gras_msg_send(temp_sock,"can_get_suc",&msg);
}CATCH(e){
RETHROW0("Unable to send!: %s");
}
RETHROW0("Unable to connect to the node wich has requested for an area!: %s");
}
TRY{
- gras_msg_send(temp_sock,gras_msgtype_by_name("can_rep_suc"),&outgoing);
+ gras_msg_send(temp_sock,"can_rep_suc",&outgoing);
INFO0("Environment informations sent!");
}CATCH(e){
RETHROW2("%s:Timeout sending environment informations to %s: %s",globals->host,gras_socket_peer_name(expeditor));
INFO4("My area is [%d;%d;%d;%d]",globals->x1,globals->x2,globals->y1,globals->y2);
//INFO0("Closing node, all has been done!");
}
- return 1;
+ return 0;
}
strcpy(get_suc_msg.host,globals->host);
get_suc_msg.port=globals->port;
TRY{ // asking.
- gras_msg_send(temp_sock,gras_msgtype_by_name("can_get_suc"),&get_suc_msg);
+ gras_msg_send(temp_sock,"can_get_suc",&get_suc_msg);
}CATCH(e){
gras_socket_close(temp_sock);
RETHROW0("Unable to contact known host to get an area!: %s");
gras_socket_t temp_sock2=NULL;
TRY{ // waiting for a reply.
INFO0("Waiting for reply!");
- gras_msg_wait(6000,gras_msgtype_by_name("can_rep_suc"),&temp_sock2,&rep_suc_msg);
+ gras_msg_wait(6000,"can_rep_suc",&temp_sock2,&rep_suc_msg);
}CATCH(e){
RETHROW1("%s: Error waiting for an area:%s",globals->host);
}
nuke_msg.port=atoi(argv[1]);
TRY{
- gras_msg_send(temp_sock,gras_msgtype_by_name("can_nuke"),&nuke_msg);
+ gras_msg_send(temp_sock,"can_nuke",&nuke_msg);
}CATCH(e){
gras_socket_close(temp_sock);
RETHROW0("Unable to contact known host so as to declare WAR!!!!!!!!!!!!!!!!!!!!!: %s");
}
//INFO4("%s ON %s %d %d <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<",globals->host,host,xId,yId);
TRY{
- gras_msg_send(temp_sock,gras_msgtype_by_name("can_nuke"),msg);
+ gras_msg_send(temp_sock,"can_nuke",msg);
}CATCH(e){
RETHROW0("Unable to send the nuke!: %s");
}
RETHROW0("Unable to connect the nuke!: %s");
}
TRY{
- gras_msg_send(temp_sock,gras_msgtype_by_name("can_nuke"),incoming);
+ gras_msg_send(temp_sock,"can_nuke",incoming);
}CATCH(e){
RETHROW0("Unable to send the nuke!: %s");
}
INFO4("My area is [%d;%d;%d;%d]",globals->x1,globals->x2,globals->y1,globals->y2);
//INFO0("Closing node, all has been done!");
}
- return 1;
+ return 0;
}
// END
RETHROW0("Unable to connect!: %s");
}
TRY{
- gras_msg_send(temp_sock,gras_msgtype_by_name("chord_get_suc"),&asking);
+ gras_msg_send(temp_sock,"chord_get_suc",&asking);
}CATCH(e){
RETHROW0("Unable to ask!: %s");
}
- gras_msg_wait(10.,gras_msgtype_by_name("chord_rep_suc"),&temp_sock,
- &outgoing);
+ gras_msg_wait(10.,"chord_rep_suc",&temp_sock, &outgoing);
}
}
TRY{
- gras_msg_send(expeditor,gras_msgtype_by_name("chord_rep_suc"),&outgoing);
+ gras_msg_send(expeditor,"chord_rep_suc",&outgoing);
INFO0("Successor information sent!");
}CATCH(e){
RETHROW2("%s:Timeout sending successor information to %s: %s",
globals->host,gras_socket_peer_name(expeditor));
}
gras_socket_close(expeditor);
- return(1);
+ return 0;
}
static int closest_preceding_node(int id){
globals->pre_port=incoming.port;
INFO0("Set as my new predecessor!");
}
- return(1);
+ return 0;
}
static void fix_fingers(){
}
get_suc_t get_suc_msg;get_suc_msg.id=globals->id;
TRY{
- gras_msg_send(temp_sock,gras_msgtype_by_name("chord_get_suc"),&get_suc_msg);
+ gras_msg_send(temp_sock,"chord_get_suc",&get_suc_msg);
}CATCH(e){
gras_socket_close(temp_sock);
RETHROW0("Unable to contact known host to get successor!: %s");
rep_suc_t rep_suc_msg;
TRY{
INFO0("Waiting for reply!");
- gras_msg_wait(6000,gras_msgtype_by_name("chord_rep_suc"),&temp_sock2,
- &rep_suc_msg);
+ gras_msg_wait(6000,"chord_rep_suc",&temp_sock2, &rep_suc_msg);
}CATCH(e){
RETHROW1("%s: Error waiting for successor:%s",globals->host);
}
pong_t pong;
ping.id = 0;
TRY{
- gras_msg_send( temp_sock, gras_msgtype_by_name("chord_ping"),&ping);
+ gras_msg_send( temp_sock, "chord_ping",&ping);
}CATCH(e){
globals->pre_id = -1;
globals->pre_host[0] = 0;
globals->pre_port = 0;
}
TRY{
- gras_msg_wait( 60, gras_msgtype_by_name("chord_pong"), &temp_sock, &pong);
+ gras_msg_wait( 60, "chord_pong", &temp_sock, &pong);
}CATCH(e){
globals->pre_id = -1;
globals->pre_host[0] = 0;
}
get_suc_t get_suc_msg;get_suc_msg.id=globals->id;
TRY{
- gras_msg_send(temp_sock,gras_msgtype_by_name("chord_get_suc"),
- &get_suc_msg);
+ gras_msg_send(temp_sock,"chord_get_suc", &get_suc_msg);
}CATCH(e){
gras_socket_close(temp_sock);
RETHROW0("Unable to contact known host to get successor!: %s");
rep_suc_t rep_suc_msg;
TRY{
INFO0("Waiting for reply!");
- gras_msg_wait(10.,gras_msgtype_by_name("chord_rep_suc"),&temp_sock2,
- &rep_suc_msg);
+ gras_msg_wait(10.,"chord_rep_suc",&temp_sock2, &rep_suc_msg);
}CATCH(e){
RETHROW1("%s: Error waiting for successor:%s",globals->host);
}
snprintf(notify_msg.host,1024,globals->host);
notify_msg.port=globals->port;
TRY{
- gras_msg_send(temp_sock,gras_msgtype_by_name("chord_notify"),¬ify_msg);
+ gras_msg_send(temp_sock,"chord_notify",¬ify_msg);
}CATCH(e){
RETHROW0("Unable to notify successor! %s");
}
gras_cb_register("chord_get_suc", &node_cb_get_suc_handler);
gras_cb_register("chord_notify", &node_cb_notify_handler);
- /*gras_cb_register(gras_msgtype_by_name("chord_ping"),&node_cb_ping_handler);*/
+ /*gras_cb_register("chord_ping",&node_cb_ping_handler);*/
/* gras_timer_repeat(600.,fix_fingers);*/
/*while(1){*/
int l;
/* 7. Prepare and send the ping message to the server */
ping = 1234;
TRY {
- gras_msg_send(toserver, gras_msgtype_by_name("ping"), &ping);
+ gras_msg_send(toserver, "ping", &ping);
} CATCH(e) {
gras_socket_close(toserver);
RETHROW0("Failed to send PING to server: %s");
/* 8. Wait for the answer from the server, and deal with issues */
TRY {
- gras_msg_wait(6000,gras_msgtype_by_name("pong"),
- &from,&pong);
+ gras_msg_wait(6000,"pong", &from,&pong);
} CATCH(e) {
gras_socket_close(toserver);
RETHROW0("Why can't I get my PONG message like everyone else: %s");
msg = 4321;
/* 5. Send it back as payload of a pong message to the expeditor */
TRY {
- gras_msg_send(expeditor, gras_msgtype_by_name("pong"), &msg);
+ gras_msg_send(expeditor, "pong", &msg);
/* 6. Deal with errors: add some details to the exception */
} CATCH(e) {
gras_socket_close(expeditor);
/* 9. Tell GRAS that we consummed this message */
- return 1;
+ return 0;
} /* end_of_server_cb_ping_handler */
int server (int argc,char *argv[]) {
line++;
}
- gras_msg_send(socket[i],gras_msgtype_by_name("pmm_slave"),&assignment);
+ gras_msg_send(socket[i],"pmm_slave",&assignment);
xbt_matrix_free(assignment.A);
xbt_matrix_free(assignment.B);
}
/* Retrieve the results */
for( i=0;i< SLAVE_COUNT;i++){
- gras_msg_wait(6000,gras_msgtype_by_name("result"),&from,&result);
+ gras_msg_wait(6000,"result",&from,&result);
VERB2("%d slaves are done already. Waiting for %d",i+1, SLAVE_COUNT);
xbt_matrix_copy_values(C,result.C, submatrix_size,submatrix_size,
submatrix_size*result.linepos,
INFO2("LINE: Send to %s:%d",
gras_socket_peer_name(socket_row[l]),
gras_socket_peer_port(socket_row[l]));
- gras_msg_send(socket_row[l],
- gras_msgtype_by_name("dataB"),
- &mydataB);
+ gras_msg_send(socket_row[l], "dataB", &mydataB);
}
} else {
TRY {
xbt_matrix_free(bB);
- gras_msg_wait(600,gras_msgtype_by_name("dataB"),&from,&bB);
+ gras_msg_wait(600,"dataB",&from,&bB);
} CATCH(e) {
RETHROW0("Can't get a data message from line : %s");
}
INFO2("ROW: Send to %s:%d",
gras_socket_peer_name(socket_line[l-1]),
gras_socket_peer_port(socket_line[l-1]));
- gras_msg_send(socket_line[l-1],gras_msgtype_by_name("dataA"), &mydataA);
+ gras_msg_send(socket_line[l-1],"dataA", &mydataA);
}
xbt_matrix_free(bA);
bA = xbt_matrix_new_sub(mydataA,
} else {
TRY {
xbt_matrix_free(bA);
- gras_msg_wait(1200,gras_msgtype_by_name("dataA"), &from,&bA);
+ gras_msg_wait(1200,"dataA", &from,&bA);
} CATCH(e) {
RETHROW0("Can't get a data message from row : %s");
}
result.rowpos=myrow;
TRY {
- gras_msg_send(master, gras_msgtype_by_name("result"),&result);
+ gras_msg_send(master, "result",&result);
} CATCH(e) {
RETHROW0("Failed to send answer to server: %s");
}
gras_socket_close(socket_row[l]);
}*/
- return 1;
+ return 0;
}
int slave(int argc,char *argv[]) {
ping = 1234;
TRY {
exception_catching();
- gras_msg_rpccall(toserver, 6000.0,
- gras_msgtype_by_name("plain ping"), &ping, &pong);
+ gras_msg_rpccall(toserver, 6000.0, "plain ping", &ping, &pong);
} CATCH(e) {
gras_socket_close(toserver);
RETHROW0("Failed to execute a PING rpc on the server: %s");
/* 9. Call a RPC which raises an exception (to test exception propagation) */
INFO0("Call the exception raising RPC");
TRY {
- gras_msg_rpccall(toserver, 6000.0,
- gras_msgtype_by_name("raise exception"), NULL, NULL);
+ gras_msg_rpccall(toserver, 6000.0, "raise exception", NULL, NULL);
} CATCH(e) {
gotit = 1;
xbt_assert2(e.category == unknown_error,
INFO1("Call the exception raising RPC (i=%d)",i);
TRY {
- gras_msg_rpccall(toserver, 6000.0,
- gras_msgtype_by_name("raise exception"), NULL, NULL);
+ gras_msg_rpccall(toserver, 6000.0, "raise exception", NULL, NULL);
} CATCH(e) {
gotit = 1;
xbt_ex_free(e);
for (i=0;i<5;i++) {
INFO1("Call the exception raising RPC on the forwarder (i=%d)",i);
TRY {
- gras_msg_rpccall(toforwarder, 6000.0,
- gras_msgtype_by_name("forward exception"), NULL, NULL);
+ gras_msg_rpccall(toforwarder, 6000.0, "forward exception", NULL, NULL);
} CATCH(e) {
gotit = 1;
}
}
INFO2("Ask %s:%d to die",gras_socket_peer_name(toforwarder),gras_socket_peer_port(toforwarder));
- gras_msg_send(toforwarder,gras_msgtype_by_name("kill"),NULL);
+ gras_msg_send(toforwarder,"kill",NULL);
INFO2("Ask %s:%d to die",gras_socket_peer_name(toserver),gras_socket_peer_port(toserver));
- gras_msg_send(toserver,gras_msgtype_by_name("kill"),NULL);
+ gras_msg_send(toserver,"kill",NULL);
/* 11. Cleanup the place before leaving */
gras_socket_close(toserver);
INFO2("Asked to die by %s:%d",gras_socket_peer_name(expeditor),gras_socket_peer_port(expeditor));
forward_data_t fdata=gras_userdata_get();
fdata->done = 1;
- return 1;
+ return 0;
}
static int forwarder_cb_forward_ex(gras_msg_cb_ctx_t ctx,
forward_data_t fdata=gras_userdata_get();
INFO0("Forward a request");
- gras_msg_rpccall(fdata->server, 60,
- gras_msgtype_by_name("raise exception"),NULL,NULL);
- return 1;
+ gras_msg_rpccall(fdata->server, 60, "raise exception",NULL,NULL);
+ return 0;
}
int forwarder (int argc,char *argv[]) {
server_data_t sdata=gras_userdata_get();
sdata->done = 1;
- return 1;
+ return 0;
}
static int server_cb_raise_ex(gras_msg_cb_ctx_t ctx,
void *payload_data) {
exception_raising();
- return 1;
+ return 0;
}
static int server_cb_ping(gras_msg_cb_ctx_t ctx,
/* 6. Cleanups, if any */
/* 7. Tell GRAS that we consummed this message */
- return 1;
+ return 0;
} /* end_of_server_cb_ping */
request->buf_size,request->msg_size,request->msg_amount);
TRY {
- gras_msg_rpccall(peer,15,
- gras_msgtype_by_name("BW handshake"),&request, &request_ack);
+ gras_msg_rpccall(peer,15,"BW handshake",&request, &request_ack);
} CATCH(e) {
RETHROW0("Error encountered while sending the BW request: %s");
}
request->msg_size, request->msg_amount,
((double)request->msg_size) * ((double)request->msg_amount / (*sec) /1024.0/1024.0));
- gras_msg_rpccall(peer, 60, gras_msgtype_by_name("BW reask"),&request, NULL);
+ gras_msg_rpccall(peer, 60, "BW reask",&request, NULL);
}
first_pass = 0;
DEBUG2("This measurement was long enough (%f sec; found %f b/s). Stop peer",
*sec,*bw);
- gras_msg_send(peer, gras_msgtype_by_name("BW stop"), NULL);
+ gras_msg_send(peer, "BW stop", NULL);
free(request_ack);
free(request);
free(answer);
free(request);
VERB0("BW experiment done.");
- return 1;
+ return 0;
}
/**
DEBUG4("Ask for a BW test between %s:%d and %s:%d", from_name,from_port, to_name,to_port);
- gras_msg_rpccall(sock,20*60,gras_msgtype_by_name("BW request"), &request, &result);
+ gras_msg_rpccall(sock,20*60,"BW request", &request, &result);
if (sec)
*sec=result->sec;
free(request);
free(result);
- return 1;
+ return 0;
}
/** \brief builds a matrix of results of bandwidth measurement
request->duration=duration;
request->msg_size=msg_size;
- gras_msg_rpccall(sock,60,gras_msgtype_by_name("amok_bw_sat start"),&request, NULL);
+ gras_msg_rpccall(sock,60,"amok_bw_sat start",&request, NULL);
free(request);
gras_socket_close(sock);
free(request->peer.name);
free(request);
- return 1;
+ return 0;
}
/**
/* Launch the saturation */
- ctx = gras_msg_rpc_async_call(peer_cmd, 60,
- gras_msgtype_by_name("amok_bw_sat begin"),
- &request);
+ ctx = gras_msg_rpc_async_call(peer_cmd, 60, "amok_bw_sat begin", &request);
free(request);
gras_msg_rpc_async_wait(ctx,&request);
meas=gras_socket_client_ext( to_name, request->peer.port,
/* Check whether someone asked us to stop saturation */
saturate_further = 0;
TRY {
- gras_msg_wait_ext(0/*no wait*/,gras_msgtype_by_name("amok_bw_sat stop"),
+ gras_msg_wait_ext(0/*no wait*/,"amok_bw_sat stop",
NULL /* accept any sender */,
NULL, NULL, /* No specific filter */
&msg_got);
if (gras_if_RL()) /* On SG, accepted=master */
gras_socket_close(measMaster);
free(request);
- return 1;
+ return 0;
}
/**
bw_res_t answer;
VERB2("Ask %s:%d to stop the saturation",from_name,from_port);
TRY {
- gras_msg_rpccall(sock,60,gras_msgtype_by_name("amok_bw_sat stop"),NULL,&answer);
+ gras_msg_rpccall(sock,60,"amok_bw_sat stop",NULL,&answer);
} CATCH(e) {
RETHROW2("Cannot ask %s:%d to stop saturation: %s",from_name, from_port);
}
amok_pm_moddata_t g=gras_moddata_by_id(amok_pm_moddata_id);
g->done = 1;
- return 1;
+ return 0;
}
static int amok_pm_cb_killrpc(gras_msg_cb_ctx_t ctx,
void *payload_data) {
amok_pm_moddata_t g=gras_moddata_by_id(amok_pm_moddata_id);
g->done = 1;
gras_msg_rpcreturn(30,ctx,NULL);
- return 1;
+ return 0;
}
static int amok_pm_cb_get(gras_msg_cb_ctx_t ctx, void *payload) {
xbt_dynar_t res = xbt_dict_get(g->groups, name);
gras_msg_rpcreturn(30, ctx, &res);
- return 1;
+ return 0;
}
static int amok_pm_cb_join(gras_msg_cb_ctx_t ctx, void *payload) {
amok_pm_moddata_t g=gras_moddata_by_id(amok_pm_moddata_id);
gras_msg_rpcreturn(10, ctx, NULL);
free(name);
- return 1;
+ return 0;
}
static int amok_pm_cb_leave(gras_msg_cb_ctx_t ctx, void *payload) {
amok_pm_moddata_t g=gras_moddata_by_id(amok_pm_moddata_id);
end:
gras_msg_rpcreturn(30, ctx, NULL);
- return 1;
+ return 0;
}
static int amok_pm_cb_shutdown(gras_msg_cb_ctx_t ctx, void *payload) {
amok_pm_group_shutdown(name);
gras_msg_rpcreturn(30, ctx, NULL);
- return 1;
+ return 0;
}
/** \brief Enter the main loop of the program. It won't return until we get a kill message. */
/** \brief kill a buddy to which we have a socket already. Note that it is not removed from any group it may belong to. */
void amok_pm_kill(gras_socket_t buddy) {
- gras_msg_send(buddy,gras_msgtype_by_name("amok_pm_kill"),NULL);
+ gras_msg_send(buddy,"amok_pm_kill",NULL);
}
/** \brief kill syncronously a buddy (do not return before its death). Note that it is not removed from any group it may belong to. */
void amok_pm_kill_sync(gras_socket_t buddy) {
- gras_msg_rpccall(buddy,30,gras_msgtype_by_name("amok_pm_killrpc"),NULL,NULL);
+ gras_msg_rpccall(buddy,30,"amok_pm_killrpc",NULL,NULL);
}
xbt_dynar_t amok_pm_group_get(gras_socket_t master, const char *group_name) {
xbt_dynar_t res;
- gras_msg_rpccall(master,30,gras_msgtype_by_name("amok_pm_get"),
- &group_name,&res);
+ gras_msg_rpccall(master,30,"amok_pm_get", &group_name,&res);
return res;
}
void amok_pm_group_join(gras_socket_t master, const char *group_name) {
VERB3("Join group '%s' on %s:%d",
group_name,gras_socket_peer_name(master),gras_socket_peer_port(master));
- gras_msg_rpccall(master,30,gras_msgtype_by_name("amok_pm_join"),
- &group_name,NULL);
+ gras_msg_rpccall(master,30,"amok_pm_join", &group_name,NULL);
VERB3("Joined group '%s' on %s:%d",
group_name,gras_socket_peer_name(master),gras_socket_peer_port(master));
}
* If not found, call is ignored
*/
void amok_pm_group_leave(gras_socket_t master, const char *group_name) {
- gras_msg_rpccall(master,30,gras_msgtype_by_name("amok_pm_leave"),
- &group_name,NULL);
+ gras_msg_rpccall(master,30,"amok_pm_leave", &group_name,NULL);
VERB3("Leaved group '%s' on %s:%d",
group_name,gras_socket_peer_name(master),gras_socket_peer_port(master));
}
}
/** \brief stops all members of the given remote group */
void amok_pm_group_shutdown_remote(gras_socket_t master, const char *group_name){
- gras_msg_rpccall(master,30,gras_msgtype_by_name("amok_pm_shutdown"),
- &group_name,NULL);
+ gras_msg_rpccall(master,30,"amok_pm_shutdown", &group_name,NULL);
}