svc2-server.c 3.78 KB
Newer Older
1 2 3 4 5 6 7
/*
 * (C) 2015 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */

#include <assert.h>
8
#include <pthread.h>
Philip Carns's avatar
Philip Carns committed
9 10
#include "svc2-proto.h"
#include "svc2-server.h"
11 12 13 14 15 16 17 18 19

static void svc2_do_thing_ult(hg_handle_t handle)
{
    hg_return_t hret;
    svc2_do_thing_out_t out;
    svc2_do_thing_in_t in;
    hg_size_t size;
    void *buffer;
    hg_bulk_t bulk_handle;
Philip Carns's avatar
Philip Carns committed
20
    const struct hg_info *hgi;
21
    margo_instance_id mid;
22 23 24
    ABT_thread my_ult;
    ABT_xstream my_xstream; 
    pthread_t my_tid;
25

26 27 28
    hret = margo_get_input(handle, &in);
    assert(hret == HG_SUCCESS);
    hgi = margo_get_info(handle);
29
    assert(hgi);
30 31
    mid = margo_hg_info_get_instance(hgi);
    assert(mid != MARGO_INSTANCE_NULL);
32 33 34 35

    ABT_xstream_self(&my_xstream);
    ABT_thread_self(&my_ult);
    my_tid = pthread_self();
Philip Carns's avatar
Philip Carns committed
36
    printf("svc2: do_thing: mplex_id: %u, ult: %p, xstream %p, tid: %lu\n", 
37
        hgi->target_id, my_ult, my_xstream, my_tid);
38 39 40 41 42 43 44 45 46

    out.ret = 0;

    /* set up target buffer for bulk transfer */
    size = 512;
    buffer = calloc(1, 512);
    assert(buffer);

    /* register local target buffer for bulk access */
47
    hret = margo_bulk_create(mid, 1, &buffer,
48
        &size, HG_BULK_WRITE_ONLY, &bulk_handle);
49
    assert(hret == HG_SUCCESS);
50 51

    /* do bulk transfer from client to server */
52
    hret = margo_bulk_transfer(mid, HG_BULK_PULL,
53
        hgi->addr, in.bulk_handle, 0,
54 55
        bulk_handle, 0, size, HG_OP_ID_IGNORE);
    assert(hret == HG_SUCCESS);
56

57
    margo_free_input(handle, &in);
58

59
    hret = margo_respond(mid, handle, &out);
60 61
    assert(hret == HG_SUCCESS);

62
    margo_bulk_free(bulk_handle);
Shane Snyder's avatar
Shane Snyder committed
63
    margo_destroy(mid, handle);
64 65 66 67 68 69 70 71 72 73 74 75 76 77
    free(buffer);

    return;
}
DEFINE_MARGO_RPC_HANDLER(svc2_do_thing_ult)

static void svc2_do_other_thing_ult(hg_handle_t handle)
{
    hg_return_t hret;
    svc2_do_other_thing_out_t out;
    svc2_do_other_thing_in_t in;
    hg_size_t size;
    void *buffer;
    hg_bulk_t bulk_handle;
Philip Carns's avatar
Philip Carns committed
78
    const struct hg_info *hgi;
79
    margo_instance_id mid;
80 81 82
    ABT_thread my_ult;
    ABT_xstream my_xstream; 
    pthread_t my_tid;
83

84 85 86
    hret = margo_get_input(handle, &in);
    assert(hret == HG_SUCCESS);
    hgi = margo_get_info(handle);
87
    assert(hgi);
88 89
    mid = margo_hg_info_get_instance(hgi);
    assert(mid != MARGO_INSTANCE_NULL);
90 91 92 93

    ABT_xstream_self(&my_xstream);
    ABT_thread_self(&my_ult);
    my_tid = pthread_self();
Philip Carns's avatar
Philip Carns committed
94
    printf("svc2: do_other_thing: mplex_id: %u, ult: %p, xstream %p, tid: %lu\n", 
95
        hgi->target_id, my_ult, my_xstream, my_tid);
96 97 98 99 100 101 102 103 104

    out.ret = 0;

    /* set up target buffer for bulk transfer */
    size = 512;
    buffer = calloc(1, 512);
    assert(buffer);

    /* register local target buffer for bulk access */
105
    hret = margo_bulk_create(mid, 1, &buffer,
106
        &size, HG_BULK_WRITE_ONLY, &bulk_handle);
107
    assert(hret == HG_SUCCESS);
108 109

    /* do bulk transfer from client to server */
110
    hret = margo_bulk_transfer(mid, HG_BULK_PULL,
111
        hgi->addr, in.bulk_handle, 0,
112 113
        bulk_handle, 0, size, HG_OP_ID_IGNORE);
    assert(hret == HG_SUCCESS);
114

115
    margo_free_input(handle, &in);
116

117
    hret = margo_respond(mid, handle, &out);
118 119
    assert(hret == HG_SUCCESS);

120
    margo_bulk_free(bulk_handle);
Shane Snyder's avatar
Shane Snyder committed
121
    margo_destroy(mid, handle);
122 123 124 125 126 127 128 129
    free(buffer);

    return;
}
DEFINE_MARGO_RPC_HANDLER(svc2_do_other_thing_ult)

int svc2_register(margo_instance_id mid, ABT_pool pool, uint32_t mplex_id)
{
130 131
    MARGO_REGISTER_MPLEX(mid, "svc2_do_thing", 
        svc2_do_thing_in_t, svc2_do_thing_out_t, 
132
        svc2_do_thing_ult, mplex_id, pool);
133 134
    MARGO_REGISTER_MPLEX(mid, "svc2_do_other_thing", 
        svc2_do_other_thing_in_t, svc2_do_other_thing_out_t, 
135
        svc2_do_other_thing_ult, mplex_id, pool);
136 137 138 139 140 141 142 143 144
   
    return(0);
}

void svc2_deregister(margo_instance_id mid, ABT_pool pool, uint32_t mplex_id)
{
    /* TODO: undo what was done in svc2_register() */
    return;
}