Commit 2b66eef8 authored by Philip Carns's avatar Philip Carns

start to stub out client example

parent 1284aae8
noinst_PROGRAMS += examples/multiplex/margo-example-mp-server
noinst_PROGRAMS += examples/multiplex/margo-example-mp-server examples/multiplex/margo-example-mp-client
examples_multiplex_margo_example_mp_server_SOURCES = \
examples/multiplex/margo-example-mp-server.c \
examples/multiplex/svc1-server.c \
examples/multiplex/svc2-server.c
examples_multiplex_margo_example_mp_client_SOURCES = \
examples/multiplex/margo-example-mp-client.c \
examples/multiplex/svc1-client.c
/*
* (C) 2015 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <abt.h>
#include <abt-snoozer.h>
#include <margo.h>
#include "svc1-client.h"
static hg_id_t my_rpc_shutdown_id;
int main(int argc, char **argv)
{
int i;
int ret;
margo_instance_id mid;
hg_context_t *hg_context;
hg_class_t *hg_class;
hg_addr_t svr_addr = HG_ADDR_NULL;
hg_handle_t handle;
char proto[12] = {0};
if(argc != 2)
{
fprintf(stderr, "Usage: ./client <server_addr>\n");
return(-1);
}
/* boilerplate HG initialization steps */
/***************************************/
/* initialize Mercury using the transport portion of the destination
* address (i.e., the part before the first : character if present)
*/
for(i=0; i<11 && argv[1][i] != '\0' && argv[1][i] != ':'; i++)
proto[i] = argv[1][i];
hg_class = HG_Init(proto, HG_FALSE);
if(!hg_class)
{
fprintf(stderr, "Error: HG_Init()\n");
return(-1);
}
hg_context = HG_Context_create(hg_class);
if(!hg_context)
{
fprintf(stderr, "Error: HG_Context_create()\n");
HG_Finalize(hg_class);
return(-1);
}
/* set up argobots */
/***************************************/
ret = ABT_init(argc, argv);
if(ret != 0)
{
fprintf(stderr, "Error: ABT_init()\n");
return(-1);
}
/* set primary ES to idle without polling */
ret = ABT_snoozer_xstream_self_set();
if(ret != 0)
{
fprintf(stderr, "Error: ABT_snoozer_xstream_self_set()\n");
return(-1);
}
/* actually start margo */
/***************************************/
mid = margo_init(0, 0, hg_context);
/* register core RPC */
my_rpc_shutdown_id = MERCURY_REGISTER(hg_class, "my_shutdown_rpc", void, void,
NULL);
/* find addr for server */
ret = margo_addr_lookup(mid, argv[1], &svr_addr);
assert(ret == 0);
svc1_do_thing(mid, svr_addr, 1);
/* send one rpc to server to shut it down */
/* create handle */
ret = HG_Create(hg_context, svr_addr, my_rpc_shutdown_id, &handle);
assert(ret == 0);
margo_forward(mid, handle, NULL);
HG_Addr_free(hg_class, svr_addr);
/* shut down everything */
margo_finalize(mid);
ABT_finalize();
HG_Context_destroy(hg_context);
HG_Finalize(hg_class);
return(0);
}
/*
* (C) 2015 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <abt.h>
#include "svc1-client.h"
#include "svc1-proto.h"
/* NOTE: just making these global for test example, would be cleaner if there
* were an instance pointer for the client.
*/
static hg_id_t svc1_do_thing_id = -1;
static hg_id_t svc1_do_other_thing_id = -1;
int svc1_register_client(margo_instance_id mid)
{
svc1_do_thing_id = MERCURY_REGISTER(margo_get_class(mid), "svc1_do_thing",
svc1_do_thing_in_t, svc1_do_thing_out_t, NULL);
svc1_do_other_thing_id = MERCURY_REGISTER(margo_get_class(mid), "svc1_do_other_thing",
svc1_do_other_thing_in_t, svc1_do_other_thing_out_t, NULL);
return(0);
}
void svc1_do_thing(margo_instance_id mid, hg_addr_t svr_addr, uint32_t mplex_id)
{
hg_handle_t handle;
svc1_do_thing_in_t in;
svc1_do_thing_out_t out;
int ret;
hg_size_t size;
void* buffer;
struct hg_info *hgi;
/* allocate buffer for bulk transfer */
size = 512;
buffer = calloc(1, 512);
assert(buffer);
sprintf((char*)buffer, "Hello world!\n");
/* create handle */
ret = HG_Create(margo_get_context(mid), svr_addr, svc1_do_thing_id, &handle);
assert(ret == 0);
/* register buffer for rdma/bulk access by server */
hgi = HG_Get_info(handle);
assert(hgi);
ret = HG_Bulk_create(hgi->hg_class, 1, &buffer, &size,
HG_BULK_READ_ONLY, &in.bulk_handle);
assert(ret == 0);
hgi->mplex_id = mplex_id;
/* Send rpc. Note that we are also transmitting the bulk handle in the
* input struct. It was set above.
*/
in.input_val = 0;
margo_forward(mid, handle, &in);
/* decode response */
ret = HG_Get_output(handle, &out);
assert(ret == 0);
/* clean up resources consumed by this rpc */
HG_Bulk_free(in.bulk_handle);
HG_Free_output(handle, &out);
HG_Destroy(handle);
free(buffer);
return;
}
......@@ -9,4 +9,6 @@
#include <margo.h>
void svc1_do_thing(margo_instance_id mid, hg_addr_t svr_addr, uint32_t mplex_id);
#endif /* __SVC1_CLIENT */
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