int forwarder (int argc,char *argv[]);
int client (int argc,char *argv[]);
-#define exception_raising() \
- THROW0(unknown_error,42,"Some error we will catch on client side")
+#define exception_msg "Error for the client"
+#define exception_raising() THROW0(unknown_error,42,exception_msg)
static void exception_catching(void) {
int gotit = 0,i;
if (!gotit) {
THROW0(unknown_error,0,"Didn't got the remote exception!");
}
- xbt_assert2(e.category == unknown_error, "Got wrong category: %d (instead of %d)",
+ xbt_assert2(e.category == unknown_error, "Got wrong category: %d (instead of %d)",
e.category,unknown_error);
xbt_assert1(e.value == 42, "Got wrong value: %d (!=42)", e.value);
- xbt_assert1(!strncmp(e.msg,"Some error we will catch on client side",
- strlen("Some error we will catch on client side")),
+ xbt_assert1(!strncmp(e.msg,exception_msg, strlen(exception_msg)),
"Got wrong message: %s", e.msg);
xbt_ex_free(e);
}
/* 1. Init the GRAS's infrastructure */
gras_init(&argc, argv);
-
+
/* 2. Get the server's address. The command line override defaults when specified */
if (argc == 5) {
host=argv[1];
port=atoi(argv[2]);
- }
+ }
INFO2("Launch client (server on %s:%d)",host,port);
exception_catching();
-
+
/* 3. Wait for the server & forwarder startup */
gras_os_sleep(2);
-
+
/* 4. Create a socket to speak to the server */
TRY {
exception_catching();
} CATCH(e) {
RETHROW0("Unable to connect to the server: %s");
}
- INFO2("Connected to %s:%d.",host,port);
+ INFO2("Connected to %s:%d.",host,port);
- /* 5. Register the messages.
+ /* 5. Register the messages.
See, it doesn't have to be done completely at the beginning,
but only before use */
exception_catching();
/* 8. Keep the user informed of what's going on, again */
INFO4("The answer to PING(%d) on %s:%d is PONG(%d)",
- ping,
+ ping,
gras_socket_peer_name(toserver),gras_socket_peer_port(toserver),
pong);
TRY {
gras_msg_rpccall(toserver, 6000.0, "raise exception", NULL, NULL);
} CATCH(e) {
- gotit = 1;
- xbt_assert2(e.category == unknown_error,
- "Got wrong category: %d (instead of %d)",
+ gotit = 1;
+ xbt_assert2(e.category == unknown_error,
+ "Got wrong category: %d (instead of %d)",
e.category,unknown_error);
xbt_assert1(e.value == 42, "Got wrong value: %d (!=42)", e.value);
- xbt_assert1(!strncmp(e.msg,"Some error we will catch on client side",
- strlen("Some error we will catch on client side")),
+ xbt_assert1(!strncmp(e.msg,exception_msg,strlen(exception_msg)),
"Got wrong message: %s", e.msg);
INFO0("Got the expected exception when calling the exception raising RPC");
xbt_ex_free(e);
/* doxygen_ignore */
for (i=0; i<5; i++) {
-
+
INFO1("Call the exception raising RPC (i=%d)",i);
TRY {
gras_msg_rpccall(toserver, 6000.0, "raise exception", NULL, NULL);
}
}
/* doxygen_resume */
-
+
/* 9. Call a RPC which raises an exception (to test that exception propagation works) */
for (i=0;i<5;i++) {
INFO1("Call the exception raising RPC on the forwarder (i=%d)",i);
}
if (!gotit) {
THROW0(unknown_error,0,"Didn't got the remote exception!");
- }
+ }
xbt_assert1(e.value == 42, "Got wrong value: %d (!=42)", e.value);
- xbt_assert1(!strncmp(e.msg,"Some error we will catch on client side",
- strlen("Some error we will catch on client side")),
+ xbt_assert1(!strncmp(e.msg,exception_msg,strlen(exception_msg)),
"Got wrong message: %s", e.msg);
- xbt_assert2(e.category == unknown_error,
- "Got wrong category: %d (instead of %d)",
+ xbt_assert2(e.category == unknown_error,
+ "Got wrong category: %d (instead of %d)",
e.category,unknown_error);
INFO0("Got the expected exception when calling the exception raising RPC");
xbt_ex_free(e);
static int server_cb_ping(gras_msg_cb_ctx_t ctx,
void *payload_data) {
-
+
/* 1. Get the payload into the msg variable, and retrieve who called us */
int msg=*(int*)payload_data;
gras_socket_t expeditor = gras_msg_cb_ctx_from(ctx);
-
+
/* 2. Log which client connected */
INFO3("Got message PING(%d) from %s:%d",
- msg,
+ msg,
gras_socket_peer_name(expeditor), gras_socket_peer_port(expeditor));
-
+
/* 4. Change the value of the msg variable */
msg = 4321;
/* 5. Return as result */
gras_msg_rpcreturn(6000,ctx,&msg);
INFO0("Answered with PONG(4321)");
-
+
/* 6. Cleanups, if any */
/* 7. Tell GRAS that we consummed this message */
server_data_t sdata;
int port = 4000;
-
+
/* 1. Init the GRAS infrastructure */
gras_init(&argc,argv);
/* 2. Get the port I should listen on from the command line, if specified */
- if (argc == 2)
+ if (argc == 2)
port=atoi(argv[1]);
sdata=gras_userdata_new(s_server_data_t);
INFO1("Listening on port %d", gras_socket_my_port(mysock));
/* 5. Wait for the ping incomming messages */
-
- /** \bug if the server is gone before the forwarder tries to connect,
+
+ /** \bug if the server is gone before the forwarder tries to connect,
it dies awfully with the following message. The problem stands somewhere
at the interface between the gras_socket_t and the msg mess. There is thus
- no way for me to dive into this before this interface is rewritten
+ no way for me to dive into this before this interface is rewritten
==15875== Invalid read of size 4
==15875== at 0x408B805: find_port (transport_plugin_sg.c:68)
==15875== by 0x408BD64: gras_trp_sg_socket_client (transport_plugin_sg.c:115)
==15875== by 0x42AA549: clone (clone.S:119)
*/
while (!sdata->done) {
- gras_msg_handle(600.0);
+ gras_msg_handle(600.0);
exception_catching();
}
-
+
/* 8. Free the allocated resources, and shut GRAS down */
free(sdata);
gras_socket_close(mysock);
INFO0("Done.");
gras_exit();
-
+
return 0;
} /* end_of_server */
> Listening on port 4002
> Got message PING(1234) from 127.0.0.1:0
> Answered with PONG(4321)
+> Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to 127.0.0.1:0
+> Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to 127.0.0.1:0
+> Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to 127.0.0.1:0
+> Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to 127.0.0.1:0
+> Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to 127.0.0.1:0
+> Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to 127.0.0.1:0
+> Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to 127.0.0.1:4003
+> Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to 127.0.0.1:4003
+> Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to 127.0.0.1:4003
+> Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to 127.0.0.1:4003
+> Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to 127.0.0.1:4003
> Asked to die by 127.0.0.1:0
> Done.
> Exiting GRAS
& $SG_TEST_EXENV ./rpc_forwarder$EXEEXT 4003 127.0.0.1 4002 --log=root.fmt:%m%n $@
> Launch forwarder (port=4003)
> Forward a request
+> Propagate remote exception ('Error for the client') from 'forward exception' RPC cb back to 127.0.0.1:0
> Forward a request
+> Propagate remote exception ('Error for the client') from 'forward exception' RPC cb back to 127.0.0.1:0
> Forward a request
+> Propagate remote exception ('Error for the client') from 'forward exception' RPC cb back to 127.0.0.1:0
> Forward a request
+> Propagate remote exception ('Error for the client') from 'forward exception' RPC cb back to 127.0.0.1:0
> Forward a request
+> Propagate remote exception ('Error for the client') from 'forward exception' RPC cb back to 127.0.0.1:0
> Asked to die by 127.0.0.1:0
> Done.
> Exiting GRAS
> [Tremblay:server:(1)] [Rpc/INFO] Answered with PONG(4321)
> [Fafard:client:(3)] [Rpc/INFO] The answer to PING(1234) on Tremblay:4000 is PONG(4321)
> [Fafard:client:(3)] [Rpc/INFO] Call the exception raising RPC
+> [Tremblay:server:(1)] [gras_msg/INFO] Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to Fafard:0
> [Fafard:client:(3)] [Rpc/INFO] Got the expected exception when calling the exception raising RPC
> [Fafard:client:(3)] [Rpc/INFO] Called the exception raising RPC
> [Fafard:client:(3)] [Rpc/INFO] Call the exception raising RPC (i=0)
+> [Tremblay:server:(1)] [gras_msg/INFO] Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to Fafard:0
> [Fafard:client:(3)] [Rpc/INFO] Call the exception raising RPC (i=1)
+> [Tremblay:server:(1)] [gras_msg/INFO] Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to Fafard:0
> [Fafard:client:(3)] [Rpc/INFO] Call the exception raising RPC (i=2)
+> [Tremblay:server:(1)] [gras_msg/INFO] Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to Fafard:0
> [Fafard:client:(3)] [Rpc/INFO] Call the exception raising RPC (i=3)
+> [Tremblay:server:(1)] [gras_msg/INFO] Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to Fafard:0
> [Fafard:client:(3)] [Rpc/INFO] Call the exception raising RPC (i=4)
+> [Tremblay:server:(1)] [gras_msg/INFO] Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to Fafard:0
> [Fafard:client:(3)] [Rpc/INFO] Call the exception raising RPC on the forwarder (i=0)
> [Ginette:forwarder:(2)] [Rpc/INFO] Forward a request
+> [Tremblay:server:(1)] [gras_msg/INFO] Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to Ginette:4000
+> [Ginette:forwarder:(2)] [gras_msg/INFO] Propagate remote exception ('Error for the client') from 'forward exception' RPC cb back to Fafard:0
> [Fafard:client:(3)] [Rpc/INFO] Got the expected exception when calling the exception raising RPC
> [Fafard:client:(3)] [Rpc/INFO] Call the exception raising RPC on the forwarder (i=1)
> [Ginette:forwarder:(2)] [Rpc/INFO] Forward a request
+> [Tremblay:server:(1)] [gras_msg/INFO] Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to Ginette:4000
+> [Ginette:forwarder:(2)] [gras_msg/INFO] Propagate remote exception ('Error for the client') from 'forward exception' RPC cb back to Fafard:0
> [Fafard:client:(3)] [Rpc/INFO] Got the expected exception when calling the exception raising RPC
> [Fafard:client:(3)] [Rpc/INFO] Call the exception raising RPC on the forwarder (i=2)
> [Ginette:forwarder:(2)] [Rpc/INFO] Forward a request
+> [Tremblay:server:(1)] [gras_msg/INFO] Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to Ginette:4000
+> [Ginette:forwarder:(2)] [gras_msg/INFO] Propagate remote exception ('Error for the client') from 'forward exception' RPC cb back to Fafard:0
> [Fafard:client:(3)] [Rpc/INFO] Got the expected exception when calling the exception raising RPC
> [Fafard:client:(3)] [Rpc/INFO] Call the exception raising RPC on the forwarder (i=3)
> [Ginette:forwarder:(2)] [Rpc/INFO] Forward a request
+> [Tremblay:server:(1)] [gras_msg/INFO] Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to Ginette:4000
+> [Ginette:forwarder:(2)] [gras_msg/INFO] Propagate remote exception ('Error for the client') from 'forward exception' RPC cb back to Fafard:0
> [Fafard:client:(3)] [Rpc/INFO] Got the expected exception when calling the exception raising RPC
> [Fafard:client:(3)] [Rpc/INFO] Call the exception raising RPC on the forwarder (i=4)
> [Ginette:forwarder:(2)] [Rpc/INFO] Forward a request
+> [Tremblay:server:(1)] [gras_msg/INFO] Propagate local exception ('Error for the client') from 'raise exception' RPC cb back to Ginette:4000
+> [Ginette:forwarder:(2)] [gras_msg/INFO] Propagate remote exception ('Error for the client') from 'forward exception' RPC cb back to Fafard:0
> [Fafard:client:(3)] [Rpc/INFO] Got the expected exception when calling the exception raising RPC
> [Fafard:client:(3)] [Rpc/INFO] Ask Ginette:4000 to die
> [Fafard:client:(3)] [Rpc/INFO] Ask Tremblay:4000 to die