/** Victim. This process gets a lot of remote exceptions */ static int victim(int argc, char *argv[]) { xbt_ex_t e; msg_error_t res = MSG_OK; XBT_INFO("Let's work."); TRY { res = MSG_task_execute(MSG_task_create("Task", 1e14, 0, NULL)); if (res != MSG_OK) { XBT_INFO("The MSG_task_execute caught the exception for me and returned %d)",res); } else { xbt_die("I was expecting an exception during my execution!"); } } CATCH(e) { XBT_INFO("The received exception resumed my execution. Good. Here is it: ----------------------->8----"); xbt_ex_display(&e); XBT_INFO("(end of the first exception) ----8<------------------------"); xbt_ex_free(e); } XBT_INFO("Let's get suspended."); int gotit = 0; TRY { MSG_process_suspend(MSG_process_self()); } CATCH(e) { XBT_INFO("The received exception resumed my suspension. Good. Here is it: ----------------------->8----"); xbt_ex_display(&e); XBT_INFO("(end of the second exception) ----8<------------------------"); gotit = 1; xbt_ex_free(e); } if(!gotit) { xbt_die("I was expecting an exception during my suspension!"); } XBT_INFO("Let's sleep for 10 seconds."); TRY { res = MSG_process_sleep(10); if (res != MSG_OK) { XBT_INFO("The MSG_process_sleep caught the exception for me and returned %d)",res); } else { xbt_die("I was expecting to get an exception during my nap."); } } CATCH(e) { XBT_INFO("Got the second exception: ----------------------->8----"); xbt_ex_display(&e); XBT_INFO("(end of the third exception) ----8<------------------------"); xbt_ex_free(e); } XBT_INFO("Let's try a last time to do something on something"); MSG_process_sleep(10); XBT_INFO("That's enough now. I quit."); return 0; }
int client(int argc, char *argv[]) { gras_socket_t mysock; /* socket on which I listen */ gras_socket_t toserver; /* socket used to write to the server */ gras_init(&argc, argv); message_declaration(); mysock = gras_socket_server_range(1024, 10000, 0, 0); XBT_VERB("Client ready; listening on %d", gras_socket_my_port(mysock)); gras_os_sleep(1.5); /* sleep 1 second and half */ toserver = gras_socket_client(argv[1], atoi(argv[2])); long long_to_convert = 4321; char *string_result; XBT_INFO("Ask to convert %ld", long_to_convert); gras_msg_rpccall(toserver, 60, "convert i2a", &long_to_convert, &string_result); XBT_INFO("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; XBT_INFO("Ask to convert %s", string_to_convert); gras_msg_rpccall(toserver, 60, "convert a2i", &string_to_convert, &long_result); XBT_INFO("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, "convert a2i", &string_to_convert, &long_result); } CATCH(e) { XBT_INFO ("The server refuses to convert %s. Here is the received exception:", string_to_convert); xbt_ex_display(&e); xbt_ex_free(e); XBT_INFO("Again, previous exception was excepted"); } gras_msg_send(toserver, "done", NULL); XBT_INFO("Stopped the server"); gras_exit(); return 0; }
/* default __ex_terminate callback function */ void __xbt_ex_terminate_default(xbt_ex_t * e) { xbt_ex_display(e); abort(); }