io-chain-client.c 1.02 KB
Newer Older
Matthieu Dorier's avatar
Matthieu Dorier committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#include <assert.h>
#include <stdio.h>
#include <abt.h>
#include <abt-snoozer.h>
#include <margo.h>
#include "types.h"

/* Main function. */
int main(int argc, char** argv)
{
	if(argc != 2) {
		fprintf(stderr,"Usage: %s <server address>\n", argv[0]);
		exit(0);
	}

	/* Start Margo */
	margo_instance_id mid = margo_init("bmi+tcp", MARGO_CLIENT_MODE, 0, 0);

	/* Register a RPC function */
	hg_id_t sum_rpc_id = MARGO_REGISTER(mid, "sum", sum_in_t, sum_out_t, NULL);
	
	/* Lookup the address of the server */
	hg_addr_t svr_addr;
	margo_addr_lookup(mid, argv[1], &svr_addr);
		
	int i;
	sum_in_t args;
	for(i=0; i<4; i++) {
		args.x = 42+i*2;
		args.y = 42+i*2+1;

		hg_handle_t h;
		margo_create(mid, svr_addr, sum_rpc_id, &h);
		margo_forward(h, &args);
		
		sum_out_t resp;
		margo_get_output(h, &resp);

		printf("Got response: %d+%d = %d\n", args.x, args.y, resp.ret);

		margo_free_output(h,&resp);
		margo_destroy(h);
	}

	/* free the address */
	margo_addr_free(mid, svr_addr);

	/* shut down Margo */
    margo_finalize(mid);

	return 0;
}