1 /* numerous_rpc -- ensures that no race condition occurs when there is a */
2 /* huge amount of very small messages */
4 /* Copyright (c) 2012. The SimGrid Team. All rights reserved. */
5 /* Thanks to Soumeya Leila Hernane for reporting an issue around this */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
12 #define RPC_AMOUNT 50000 /* amount of RPC calls to do in a raw */
14 XBT_LOG_NEW_DEFAULT_CATEGORY(numerous_rpc,"logs attached to the RPC crash test");
16 int give_hostname(gras_msg_cb_ctx_t ctx, void *payload);
17 int server(int argc, char *argv[]);
18 int client(int argc, char *argv[]);
20 /*************************************/
22 /* callback used for the test */
23 int give_hostname(gras_msg_cb_ctx_t ctx, void *payload) { /* rpc, return hostname */
24 const char* myself = gras_os_myname();
26 gras_msg_rpcreturn(-1,ctx,&myself);
28 gras_socket_close(gras_msg_cb_ctx_from(ctx));
32 /*************************************/
33 int server(int argc, char *argv[]) {
37 gras_init(&argc, argv);
38 gras_msgtype_declare_rpc("give_hostname",xbt_datadesc_by_name("xbt_string_t"),xbt_datadesc_by_name("xbt_string_t"));
39 gras_cb_register("give_hostname", &give_hostname);
41 mysock = gras_socket_server(2222);
43 for (i=0;i<RPC_AMOUNT;i++)
46 gras_socket_close(mysock);
52 /* ****************** Code of the client ****************************** */
53 int client(int argc, char *argv[]) {
55 xbt_socket_t server_sock,client_sock;
56 xbt_string_t myself = xbt_strdup(gras_os_myname());
57 xbt_string_t hostname = xbt_malloc(60);
59 gras_init(&argc, argv);
60 gras_msgtype_declare_rpc("give_hostname",xbt_datadesc_by_name("xbt_string_t"),xbt_datadesc_by_name("xbt_string_t"));
62 client_sock = gras_socket_server_range(1024, 10000, 0, 0);
64 for(i=0;i<RPC_AMOUNT;i++) {
65 server_sock = gras_socket_client(argv[1], 2222);
67 XBT_INFO("iteration %ld",i);
68 gras_msg_rpccall(server_sock,-1,"give_hostname",&myself,&hostname);
69 gras_socket_close(server_sock) ;
72 gras_socket_close(client_sock);