composed-client-lib.c 3.25 KB
Newer Older
Philip Carns's avatar
Philip Carns 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
/*
 * (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 "composed-client-lib.h"
#include "delegator-proto.h"
#include "data-xfer-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 delegator_read_id = -1;
static hg_id_t data_xfer_read_id = -1;

int composed_register_client(margo_instance_id mid)
{

25 26
	delegator_read_id = MARGO_REGISTER(mid, "delegator_read", 
        delegator_read_in_t, delegator_read_out_t, NULL);
Philip Carns's avatar
Philip Carns committed
27 28 29 30 31 32 33

    return(0);
}

int data_xfer_register_client(margo_instance_id mid)
{

34 35
	data_xfer_read_id = MARGO_REGISTER(mid, "data_xfer_read", 
        data_xfer_read_in_t, data_xfer_read_out_t, NULL);
Philip Carns's avatar
Philip Carns committed
36 37 38 39

    return(0);
}

40
void composed_read(margo_instance_id mid, hg_addr_t svr_addr, void *buffer, hg_size_t buffer_sz, char *data_xfer_svc_addr_string)
Philip Carns's avatar
Philip Carns committed
41 42 43 44
{
    hg_handle_t handle;
    delegator_read_in_t in;
    delegator_read_out_t out;
45
    hg_return_t hret;
Philip Carns's avatar
Philip Carns committed
46 47

    /* create handle */
48 49
    hret = margo_create(mid, svr_addr, delegator_read_id, &handle);
    assert(hret == HG_SUCCESS);
Philip Carns's avatar
Philip Carns committed
50 51

    /* register buffer for rdma/bulk access by server */
52
    hret = margo_bulk_create(mid, 1, &buffer, &buffer_sz, 
Philip Carns's avatar
Philip Carns committed
53
        HG_BULK_WRITE_ONLY, &in.bulk_handle);
54
    assert(hret == HG_SUCCESS);
Philip Carns's avatar
Philip Carns committed
55

56 57
    in.data_xfer_svc_addr = data_xfer_svc_addr_string;

Philip Carns's avatar
Philip Carns committed
58 59 60
    /* Send rpc. Note that we are also transmitting the bulk handle in the
     * input struct.  It was set above. 
     */ 
61
    hret = margo_forward(handle, &in);
62
    assert(hret == HG_SUCCESS);
Philip Carns's avatar
Philip Carns committed
63 64

    /* decode response */
65 66
    hret = margo_get_output(handle, &out);
    assert(hret == HG_SUCCESS);
Philip Carns's avatar
Philip Carns committed
67 68

    /* clean up resources consumed by this rpc */
69 70
    margo_free_output(handle, &out);
    margo_bulk_free(in.bulk_handle);
71
    margo_destroy(handle);
Philip Carns's avatar
Philip Carns committed
72 73 74 75

    return;
}

Philip Carns's avatar
Philip Carns committed
76 77 78 79 80
void data_xfer_read(margo_instance_id mid, hg_addr_t svr_addr, void *buffer, hg_size_t buffer_sz)
{
    hg_handle_t handle;
    data_xfer_read_in_t in;
    data_xfer_read_out_t out;
81
    hg_return_t hret;
82 83 84
    hg_addr_t addr_self;
    char addr_self_string[128];
    hg_size_t addr_self_string_sz = 128;
Philip Carns's avatar
Philip Carns committed
85 86

    /* create handle */
87 88
    hret = margo_create(mid, svr_addr, data_xfer_read_id, &handle);
    assert(hret == HG_SUCCESS);
Philip Carns's avatar
Philip Carns committed
89 90

    /* register buffer for rdma/bulk access by server */
91
    hret = margo_bulk_create(mid, 1, &buffer, &buffer_sz, 
Philip Carns's avatar
Philip Carns committed
92
        HG_BULK_WRITE_ONLY, &in.bulk_handle);
93
    assert(hret == HG_SUCCESS);
94 95

    /* figure out local address */
96 97
    hret = margo_addr_self(mid, &addr_self);
    assert(hret == HG_SUCCESS);
98

99 100
    hret = margo_addr_to_string(mid, addr_self_string, &addr_self_string_sz, addr_self);
    assert(hret == HG_SUCCESS);
101 102

    in.client_addr = addr_self_string;
Philip Carns's avatar
Philip Carns committed
103 104 105 106

    /* Send rpc. Note that we are also transmitting the bulk handle in the
     * input struct.  It was set above. 
     */ 
107
    hret = margo_forward(handle, &in);
108
    assert(hret == HG_SUCCESS);
Philip Carns's avatar
Philip Carns committed
109 110

    /* decode response */
111 112
    hret = margo_get_output(handle, &out);
    assert(hret == HG_SUCCESS);
Philip Carns's avatar
Philip Carns committed
113 114

    /* clean up resources consumed by this rpc */
115 116
    margo_free_output(handle, &out);
    margo_bulk_free(in.bulk_handle);
117
    margo_destroy(handle);
118
    margo_addr_free(mid, addr_self);
Philip Carns's avatar
Philip Carns committed
119 120 121

    return;
}