svc2-server.c 3.69 KB
Newer Older
Philip Carns's avatar
Philip Carns committed
1 2 3 4 5 6 7
/*
 * (C) 2015 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */

#include <assert.h>
Philip Carns's avatar
Philip Carns committed
8
#include <pthread.h>
Philip Carns's avatar
Philip Carns committed
9 10
#include "svc2-proto.h"
#include "svc2-server.h"
Philip Carns's avatar
Philip Carns committed
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;
Philip Carns's avatar
Philip Carns committed
21
    margo_instance_id mid;
Philip Carns's avatar
Philip Carns committed
22 23 24
    ABT_thread my_ult;
    ABT_xstream my_xstream; 
    pthread_t my_tid;
Philip Carns's avatar
Philip Carns committed
25

26 27 28
    hret = margo_get_input(handle, &in);
    assert(hret == HG_SUCCESS);
    hgi = margo_get_info(handle);
Philip Carns's avatar
Philip Carns committed
29
    assert(hgi);
30 31
    mid = margo_hg_info_get_instance(hgi);
    assert(mid != MARGO_INSTANCE_NULL);
Philip Carns's avatar
Philip Carns committed
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 37
    printf("svc2: do_thing: ult: %p, xstream %p, tid: %lu\n", 
        my_ult, my_xstream, my_tid);
Philip Carns's avatar
Philip Carns committed
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,
Philip Carns's avatar
Philip Carns committed
48
        &size, HG_BULK_WRITE_ONLY, &bulk_handle);
49
    assert(hret == HG_SUCCESS);
Philip Carns's avatar
Philip Carns committed
50 51

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

57
    margo_free_input(handle, &in);
Philip Carns's avatar
Philip Carns committed
58

59
    hret = margo_respond(handle, &out);
Philip Carns's avatar
Philip Carns committed
60 61
    assert(hret == HG_SUCCESS);

62
    margo_bulk_free(bulk_handle);
63
    margo_destroy(handle);
Philip Carns's avatar
Philip Carns committed
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;
Philip Carns's avatar
Philip Carns committed
79
    margo_instance_id mid;
Philip Carns's avatar
Philip Carns committed
80 81 82
    ABT_thread my_ult;
    ABT_xstream my_xstream; 
    pthread_t my_tid;
Philip Carns's avatar
Philip Carns committed
83

84 85 86
    hret = margo_get_input(handle, &in);
    assert(hret == HG_SUCCESS);
    hgi = margo_get_info(handle);
Philip Carns's avatar
Philip Carns committed
87
    assert(hgi);
88 89
    mid = margo_hg_info_get_instance(hgi);
    assert(mid != MARGO_INSTANCE_NULL);
Philip Carns's avatar
Philip Carns committed
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 95
    printf("svc2: do_other_thing: ult: %p, xstream %p, tid: %lu\n", 
        my_ult, my_xstream, my_tid);
Philip Carns's avatar
Philip Carns committed
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,
Philip Carns's avatar
Philip Carns committed
106
        &size, HG_BULK_WRITE_ONLY, &bulk_handle);
107
    assert(hret == HG_SUCCESS);
Philip Carns's avatar
Philip Carns committed
108 109

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

115
    margo_free_input(handle, &in);
Philip Carns's avatar
Philip Carns committed
116

117
    hret = margo_respond(handle, &out);
Philip Carns's avatar
Philip Carns committed
118 119
    assert(hret == HG_SUCCESS);

120
    margo_bulk_free(bulk_handle);
121
    margo_destroy(handle);
Philip Carns's avatar
Philip Carns committed
122 123 124 125 126 127
    free(buffer);

    return;
}
DEFINE_MARGO_RPC_HANDLER(svc2_do_other_thing_ult)

Philip Carns's avatar
Philip Carns committed
128
int svc2_register(margo_instance_id mid, ABT_pool pool, uint32_t provider_id)
Philip Carns's avatar
Philip Carns committed
129
{
Philip Carns's avatar
Philip Carns committed
130
    MARGO_REGISTER_PROVIDER(mid, "svc2_do_thing", 
131
        svc2_do_thing_in_t, svc2_do_thing_out_t, 
Philip Carns's avatar
Philip Carns committed
132 133
        svc2_do_thing_ult, provider_id, pool);
    MARGO_REGISTER_PROVIDER(mid, "svc2_do_other_thing", 
134
        svc2_do_other_thing_in_t, svc2_do_other_thing_out_t, 
Philip Carns's avatar
Philip Carns committed
135
        svc2_do_other_thing_ult, provider_id, pool);
Philip Carns's avatar
Philip Carns committed
136 137 138 139
   
    return(0);
}

Philip Carns's avatar
Philip Carns committed
140
void svc2_deregister(margo_instance_id mid, ABT_pool pool, uint32_t provider_id)
Philip Carns's avatar
Philip Carns committed
141 142 143 144
{
    /* TODO: undo what was done in svc2_register() */
    return;
}