Commit bf25ea99 authored by Philip Carns's avatar Philip Carns

add example of margo server on two transports

parent a7e74cad
noinst_PROGRAMS += examples/margo-example-client examples/margo-example-server
noinst_PROGRAMS += examples/margo-example-client examples/margo-example-server examples/margo-example-server-multihome
examples_margo_example_server_SOURCES = \
examples/margo-example-server.c \
examples/my-rpc.c
examples_margo_example_server_multihome_SOURCES = \
examples/margo-example-server-multihome.c \
examples/my-rpc.c
......@@ -77,7 +77,7 @@ int main(int argc, char **argv)
fprintf(stderr, "Error: margo_init()\n");
return(-1);
}
margo_diag_start(mid);
// margo_diag_start(mid);
/* retrieve current pool to use for ULT creation */
ret = ABT_xstream_self(&xstream);
......@@ -152,7 +152,7 @@ int main(int argc, char **argv)
margo_addr_free(mid, svr_addr);
/* shut down everything */
margo_diag_dump(mid, "-", 0);
// margo_diag_dump(mid, "-", 0);
margo_finalize(mid);
return(0);
......
/*
* (C) 2015 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <mercury.h>
#include <abt.h>
#include <margo.h>
#include "my-rpc.h"
/* example server program. Starts HG engine, registers the example RPC type,
* and then executes indefinitely.
*/
int main(int argc, char **argv)
{
hg_return_t hret;
margo_instance_id mid1, mid2;
hg_addr_t addr_self;
char addr_self_string1[128];
char addr_self_string2[128];
hg_size_t addr_self_string_sz = 128;
if(argc != 3)
{
fprintf(stderr, "Usage: ./server <listen_addr1> <listen_addr2>\n");
fprintf(stderr, "Example: ./server na+sm:// ofi+tcp://\n");
return(-1);
}
/* Start two margo instances. Each uses it's own dedicated progress
* thread and executes handlers on the calling context.
*/
/***************************************/
mid1 = margo_init(argv[1], MARGO_SERVER_MODE, 1, -1);
if(mid1 == MARGO_INSTANCE_NULL)
{
fprintf(stderr, "Error: margo_init()\n");
return(-1);
}
mid2 = margo_init(argv[2], MARGO_SERVER_MODE, 1, -1);
if(mid2 == MARGO_INSTANCE_NULL)
{
fprintf(stderr, "Error: margo_init()\n");
return(-1);
}
/* figure out first listening addr */
hret = margo_addr_self(mid1, &addr_self);
if(hret != HG_SUCCESS)
{
fprintf(stderr, "Error: margo_addr_self()\n");
margo_finalize(mid1);
return(-1);
}
addr_self_string_sz = 128;
hret = margo_addr_to_string(mid1, addr_self_string1, &addr_self_string_sz, addr_self);
if(hret != HG_SUCCESS)
{
fprintf(stderr, "Error: margo_addr_to_string()\n");
margo_addr_free(mid1, addr_self);
margo_finalize(mid1);
return(-1);
}
margo_addr_free(mid1, addr_self);
/* figure out second listening addr */
hret = margo_addr_self(mid2, &addr_self);
if(hret != HG_SUCCESS)
{
fprintf(stderr, "Error: margo_addr_self()\n");
margo_finalize(mid2);
return(-1);
}
addr_self_string_sz = 128;
hret = margo_addr_to_string(mid2, addr_self_string2, &addr_self_string_sz, addr_self);
if(hret != HG_SUCCESS)
{
fprintf(stderr, "Error: margo_addr_to_string()\n");
margo_addr_free(mid2, addr_self);
margo_finalize(mid2);
return(-1);
}
margo_addr_free(mid2, addr_self);
fprintf(stderr, "# accepting RPCs on address \"%s\" and \"%s\"\n", addr_self_string1, addr_self_string2);
/* register RPC */
MARGO_REGISTER(mid1, "my_rpc", my_rpc_in_t, my_rpc_out_t, my_rpc_ult);
MARGO_REGISTER(mid1, "my_shutdown_rpc", void, void, my_rpc_shutdown_ult);
MARGO_REGISTER(mid2, "my_rpc", my_rpc_in_t, my_rpc_out_t, my_rpc_ult);
MARGO_REGISTER(mid2, "my_shutdown_rpc", void, void, my_rpc_shutdown_ult);
/* NOTE: there isn't anything else for the server to do at this point
* except wait for itself to be shut down. The
* margo_wait_for_finalize() call here yields to let Margo drive
* progress until that happens.
*/
margo_wait_for_finalize(mid1);
margo_wait_for_finalize(mid2);
return(0);
}
......@@ -1789,6 +1789,7 @@ static void hg_progress_fn(void* foo)
{
/* TODO: error handling */
fprintf(stderr, "WARNING: unexpected return code (%d) from HG_Progress()\n", ret);
assert(0);
}
}
else
......@@ -1827,6 +1828,7 @@ static void hg_progress_fn(void* foo)
{
/* TODO: error handling */
fprintf(stderr, "WARNING: unexpected return code (%d) from HG_Progress()\n", ret);
assert(0);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment