svc1-client.c 3.15 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * (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)
{

24 25
    svc1_do_thing_id = MARGO_REGISTER(mid, "svc1_do_thing", 
        svc1_do_thing_in_t, svc1_do_thing_out_t, NULL);
26

27 28
    svc1_do_other_thing_id = MARGO_REGISTER(mid, "svc1_do_other_thing", 
        svc1_do_other_thing_in_t, svc1_do_other_thing_out_t, NULL);
29 30 31 32

    return(0);
}

Philip Carns's avatar
Philip Carns committed
33
void svc1_do_thing(margo_instance_id mid, hg_addr_t svr_addr, uint32_t provider_id)
34 35 36 37
{
    hg_handle_t handle;
    svc1_do_thing_in_t in;
    svc1_do_thing_out_t out;
38
    hg_return_t hret;
39 40 41 42 43 44 45 46 47 48
    hg_size_t size;
    void* buffer;

    /* allocate buffer for bulk transfer */
    size = 512;
    buffer = calloc(1, 512);
    assert(buffer);
    sprintf((char*)buffer, "Hello world!\n");

    /* create handle */
49 50
    hret = margo_create(mid, svr_addr, svc1_do_thing_id, &handle);
    assert(hret == HG_SUCCESS);
51 52

    /* register buffer for rdma/bulk access by server */
53
    hret = margo_bulk_create(mid, 1, &buffer, &size, 
54
        HG_BULK_READ_ONLY, &in.bulk_handle);
55
    assert(hret == HG_SUCCESS);
56 57 58 59 60

    /* Send rpc. Note that we are also transmitting the bulk handle in the
     * input struct.  It was set above. 
     */ 
    in.input_val = 0;
61
    hret = margo_provider_forward(provider_id, handle, &in);
62
    assert(hret == HG_SUCCESS);
63 64

    /* decode response */
65 66
    hret = margo_get_output(handle, &out);
    assert(hret == HG_SUCCESS);
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);
72 73 74 75 76
    free(buffer);

    return;
}

Philip Carns's avatar
Philip Carns committed
77
void svc1_do_other_thing(margo_instance_id mid, hg_addr_t svr_addr, uint32_t provider_id)
78 79 80 81
{
    hg_handle_t handle;
    svc1_do_other_thing_in_t in;
    svc1_do_other_thing_out_t out;
82
    hg_return_t hret;
83 84 85 86 87 88 89 90 91 92
    hg_size_t size;
    void* buffer;

    /* allocate buffer for bulk transfer */
    size = 512;
    buffer = calloc(1, 512);
    assert(buffer);
    sprintf((char*)buffer, "Hello world!\n");

    /* create handle */
93 94
    hret = margo_create(mid, svr_addr, svc1_do_other_thing_id, &handle);
    assert(hret == HG_SUCCESS);
95 96

    /* register buffer for rdma/bulk access by server */
97
    hret = margo_bulk_create(mid, 1, &buffer, &size, 
98
        HG_BULK_READ_ONLY, &in.bulk_handle);
99
    assert(hret == HG_SUCCESS);
100 101 102 103 104

    /* Send rpc. Note that we are also transmitting the bulk handle in the
     * input struct.  It was set above. 
     */ 
    in.input_val = 0;
105
    hret = margo_provider_forward(provider_id, handle, &in);
106
    assert(hret == HG_SUCCESS);
107 108

    /* decode response */
109 110
    hret = margo_get_output(handle, &out);
    assert(hret == HG_SUCCESS);
111 112

    /* clean up resources consumed by this rpc */
113 114
    margo_free_output(handle, &out);
    margo_bulk_free(in.bulk_handle);
115
    margo_destroy(handle);
116 117 118 119
    free(buffer);

    return;
}