Commit 336821fb authored by Philip Carns's avatar Philip Carns
Browse files

copy example from mochi-doc

- modify to use na+sm
- add Makefile
parent 048667b0
CFLAGS += `pkg-config --cflags margo`
LDFLAGS += `pkg-config --libs margo`
all:: client server
client.o: client.c
$(CC) $(CFLAGS) -c client.c
client: client.o
$(CC) client.o -o client $(LDFLAGS)
server.o: server.c
$(CC) $(CFLAGS) -c server.c
server: server.o
$(CC) server.o -o server $(LDFLAGS)
clean::
rm -f client server client.o server.o
#include <assert.h>
#include <stdio.h>
#include <margo.h>
int main(int argc, char** argv)
{
if(argc != 2) {
fprintf(stderr,"Usage: %s <server address>\n", argv[0]);
exit(0);
}
hg_return_t ret;
margo_instance_id mid = MARGO_INSTANCE_NULL;
mid = margo_init("na+sm",MARGO_CLIENT_MODE, 0, 0);
assert(mid);
hg_id_t hello_rpc_id = MARGO_REGISTER(mid, "hello", void, void, NULL);
margo_registered_disable_response(mid, hello_rpc_id, HG_TRUE);
hg_addr_t svr_addr;
ret = margo_addr_lookup(mid, argv[1], &svr_addr);
assert(ret == HG_SUCCESS);
hg_handle_t handle;
ret = margo_create(mid, svr_addr, hello_rpc_id, &handle);
assert(ret == HG_SUCCESS);
ret = margo_forward(handle, NULL);
assert(ret == HG_SUCCESS);
ret = margo_destroy(handle);
assert(ret == HG_SUCCESS);
ret = margo_addr_free(mid, svr_addr);
assert(ret == HG_SUCCESS);
margo_finalize(mid);
return 0;
}
#include <assert.h>
#include <stdio.h>
#include <margo.h>
static const int TOTAL_RPCS = 4;
static int num_rpcs = 0;
static void hello_world(hg_handle_t h);
DECLARE_MARGO_RPC_HANDLER(hello_world)
int main(int argc, char** argv)
{
margo_instance_id mid = margo_init("na+sm", MARGO_SERVER_MODE, 0, -1);
assert(mid);
hg_addr_t my_address;
margo_addr_self(mid, &my_address);
char addr_str[128];
size_t addr_str_size = 128;
margo_addr_to_string(mid, addr_str, &addr_str_size, my_address);
margo_addr_free(mid,my_address);
printf("Server running at address %s\n", addr_str);
hg_id_t rpc_id = MARGO_REGISTER(mid, "hello", void, void, hello_world);
margo_registered_disable_response(mid, rpc_id, HG_TRUE);
margo_wait_for_finalize(mid);
return 0;
}
static void hello_world(hg_handle_t h)
{
hg_return_t ret;
margo_instance_id mid = margo_hg_handle_get_instance(h);
printf("Hello World!\n");
num_rpcs += 1;
ret = margo_destroy(h);
assert(ret == HG_SUCCESS);
if(num_rpcs == TOTAL_RPCS) {
margo_finalize(mid);
}
}
DEFINE_MARGO_RPC_HANDLER(hello_world)
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