int main(int argc, char *argv[]) { unsigned int number_of_peers; unsigned int i; int hg_ret; /* Initialize the interface */ network_class = HG_Test_server_init(argc, argv, NULL, NULL, &number_of_peers); hg_ret = HG_Init(network_class); if (hg_ret != HG_SUCCESS) { fprintf(stderr, "Could not initialize Mercury\n"); return EXIT_FAILURE; } /* Register routine */ MERCURY_HANDLER_REGISTER("bla_write", fs_bla_write, bla_write_in_t, bla_write_out_t); for (i = 0; i < number_of_peers; i++) { /* Receive new function calls */ hg_ret = HG_Handler_process(HG_MAX_IDLE_TIME, HG_STATUS_IGNORE); if (hg_ret != HG_SUCCESS) { fprintf(stderr, "Could not receive function call\n"); return EXIT_FAILURE; } } printf("Finalizing...\n"); hg_ret = HG_Finalize(); if (hg_ret != HG_SUCCESS) { fprintf(stderr, "Could not finalize Mercury\n"); return EXIT_FAILURE; } HG_Test_finalize(network_class); return EXIT_SUCCESS; }
int main(void) { const char *na_info_string = NULL; char target_addr_string[PATH_MAX], *p; FILE *na_config = NULL; struct snappy_lookup_args snappy_lookup_args; hg_class_t *hg_class; hg_context_t *hg_context; hg_return_t hg_ret; /* Get info string */ na_info_string = getenv(HG_PORT_NAME); if (!na_info_string) { fprintf(stderr, HG_PORT_NAME " environment variable must be set"); exit(0); } printf("Using %s\n", na_info_string); /* Initialize Mercury with the desired network abstraction class */ hg_class = HG_Init(na_info_string, NA_FALSE); /* Create HG context */ hg_context = HG_Context_create(hg_class); /* The connection string is generated after NA_Addr_self()/NA_Addr_to_string(), * we must get that string and pass it to NA_Addr_lookup() */ na_config = fopen(TEMP_DIRECTORY CONFIG_FILE_NAME, "r"); if (!na_config) { fprintf(stderr, "Could not open config file from: %s\n", TEMP_DIRECTORY CONFIG_FILE_NAME); exit(0); } fgets(target_addr_string, PATH_MAX, na_config); p = strrchr(target_addr_string, '\n'); if (p != NULL) *p = '\0'; printf("Target address is: %s\n", target_addr_string); fclose(na_config); /* Look up target address */ snappy_lookup_args.hg_class = hg_class; snappy_lookup_args.hg_context = hg_context; HG_Addr_lookup(hg_context, snappy_lookup_cb, &snappy_lookup_args, target_addr_string, HG_OP_ID_IGNORE); /* Poke progress engine and check for events */ do { unsigned int actual_count = 0; do { hg_ret = HG_Trigger(hg_context, 0 /* timeout */, 1 /* max count */, &actual_count); } while ((hg_ret == HG_SUCCESS) && actual_count); /* Do not try to make progress anymore if we're done */ if (snappy_compress_done_g) break; hg_ret = HG_Progress(hg_context, HG_MAX_IDLE_TIME); } while (hg_ret == HG_SUCCESS); /* Finalize */ HG_Addr_free(hg_class, snappy_lookup_args.hg_target_addr); HG_Context_destroy(hg_context); HG_Finalize(hg_class); return EXIT_SUCCESS; }