svc2-server.c 3.63 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 20

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;
    int ret;
    hg_size_t size;
    void *buffer;
    hg_bulk_t bulk_handle;
Philip Carns's avatar
Philip Carns committed
21
    const struct hg_info *hgi;
Philip Carns's avatar
Philip Carns committed
22
    margo_instance_id mid;
Philip Carns's avatar
Philip Carns committed
23 24 25
    ABT_thread my_ult;
    ABT_xstream my_xstream; 
    pthread_t my_tid;
Philip Carns's avatar
Philip Carns committed
26 27 28

    ret = HG_Get_input(handle, &in);
    assert(ret == HG_SUCCESS);
Philip Carns's avatar
Philip Carns committed
29 30 31 32 33 34
    hgi = HG_Get_info(handle);
    assert(hgi);

    ABT_xstream_self(&my_xstream);
    ABT_thread_self(&my_ult);
    my_tid = pthread_self();
Philip Carns's avatar
typo  
Philip Carns committed
35
    printf("svc2: do_thing: mplex_id: %u, ult: %p, xstream %p, tid: %lu\n", 
36
        hgi->target_id, my_ult, my_xstream, my_tid);
Philip Carns's avatar
Philip Carns committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

    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 */
    ret = HG_Bulk_create(hgi->hg_class, 1, &buffer,
        &size, HG_BULK_WRITE_ONLY, &bulk_handle);
    assert(ret == 0);

    mid = margo_hg_class_to_instance(hgi->hg_class);

    /* do bulk transfer from client to server */
    ret = margo_bulk_transfer(mid, HG_BULK_PULL,
        hgi->addr, in.bulk_handle, 0,
        bulk_handle, 0, size);
    assert(ret == 0);

    HG_Free_input(handle, &in);

    hret = HG_Respond(handle, NULL, NULL, &out);
    assert(hret == HG_SUCCESS);

    HG_Bulk_free(bulk_handle);
    HG_Destroy(handle);
    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;
    int ret;
    hg_size_t size;
    void *buffer;
    hg_bulk_t bulk_handle;
Philip Carns's avatar
Philip Carns committed
80
    const struct hg_info *hgi;
Philip Carns's avatar
Philip Carns committed
81
    margo_instance_id mid;
Philip Carns's avatar
Philip Carns committed
82 83 84
    ABT_thread my_ult;
    ABT_xstream my_xstream; 
    pthread_t my_tid;
Philip Carns's avatar
Philip Carns committed
85 86 87

    ret = HG_Get_input(handle, &in);
    assert(ret == HG_SUCCESS);
Philip Carns's avatar
Philip Carns committed
88 89 90 91 92 93
    hgi = HG_Get_info(handle);
    assert(hgi);

    ABT_xstream_self(&my_xstream);
    ABT_thread_self(&my_ult);
    my_tid = pthread_self();
Philip Carns's avatar
typo  
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);
Philip Carns's avatar
Philip Carns committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

    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 */
    ret = HG_Bulk_create(hgi->hg_class, 1, &buffer,
        &size, HG_BULK_WRITE_ONLY, &bulk_handle);
    assert(ret == 0);

    mid = margo_hg_class_to_instance(hgi->hg_class);

    /* do bulk transfer from client to server */
    ret = margo_bulk_transfer(mid, HG_BULK_PULL,
        hgi->addr, in.bulk_handle, 0,
        bulk_handle, 0, size);
    assert(ret == 0);

    HG_Free_input(handle, &in);

    hret = HG_Respond(handle, NULL, NULL, &out);
    assert(hret == HG_SUCCESS);

    HG_Bulk_free(bulk_handle);
    HG_Destroy(handle);
    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)
{
    MARGO_REGISTER(mid, "svc2_do_thing", svc2_do_thing_in_t, svc2_do_thing_out_t, svc2_do_thing_ult_handler, mplex_id, pool);
    MARGO_REGISTER(mid, "svc2_do_other_thing", svc2_do_other_thing_in_t, svc2_do_other_thing_out_t, svc2_do_other_thing_ult_handler, mplex_id, pool);
   
    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;
}