GitLab maintenance scheduled for Tomorrow, 2020-01-30, from 17:00 to 18:00 CT - Services will be unavailable during this time.

composed-svc-daemon.c 3.85 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*
 * (C) 2015 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */

#include <stdio.h>
#include <assert.h>
#include <unistd.h>
Philip Carns's avatar
Philip Carns committed
10 11 12
#include <string.h>
#include <stdlib.h>

13 14 15 16
#include <abt.h>
#include <margo.h>

#include "data-xfer-service.h"
Philip Carns's avatar
Philip Carns committed
17
#include "delegator-service.h"
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

/* server program that starts a skeleton for sub-services within
 * this process to register with
 */

/* this is a "common" rpc that is handled by the core daemon
 */

static void my_rpc_shutdown_ult(hg_handle_t handle)
{
    hg_return_t hret;
    margo_instance_id mid;

    //printf("Got RPC request to shutdown\n");

33
    mid = margo_hg_handle_get_instance(handle);
34
    assert(mid != MARGO_INSTANCE_NULL);
35

36
    hret = margo_respond(handle, NULL);
37 38
    assert(hret == HG_SUCCESS);

39
    margo_destroy(handle);
40 41 42 43 44 45 46 47 48 49 50 51 52 53

    /* NOTE: we assume that the server daemon is using
     * margo_wait_for_finalize() to suspend until this RPC executes, so there
     * is no need to send any extra signal to notify it.
     */
    margo_finalize(mid);

    return;
}
DEFINE_MARGO_RPC_HANDLER(my_rpc_shutdown_ult)


int main(int argc, char **argv) 
{
54
    hg_return_t hret;
55 56 57 58 59
    margo_instance_id mid;
    hg_addr_t addr_self;
    char addr_self_string[128];
    hg_size_t addr_self_string_sz = 128;
    ABT_pool *handler_pool;
Philip Carns's avatar
Philip Carns committed
60 61
    char* svc_list;
    char* svc;
62

Philip Carns's avatar
Philip Carns committed
63
    if(argc != 3)
64
    {
Philip Carns's avatar
Philip Carns committed
65 66
        fprintf(stderr, "Usage: ./server <listen_addr> <comma_separated_service_list>\n");
        fprintf(stderr, "Example: ./server na+sm:// delegator,data-xfer\n");
67 68 69
        return(-1);
    }

Philip Carns's avatar
Philip Carns committed
70 71 72
    svc_list = strdup(argv[2]);
    assert(svc_list);

73 74 75
    /* actually start margo -- this step encapsulates the Mercury and
     * Argobots initialization and must precede their use */
    /* Use the calling xstream to drive progress and execute handlers. */
76
    /***************************************/
77 78
    mid = margo_init(argv[1], MARGO_SERVER_MODE, 0, -1);
    if(mid == MARGO_INSTANCE_NULL)
79
    {
80
        fprintf(stderr, "Error: margo_init()\n");
81 82 83 84
        return(-1);
    }

    /* figure out what address this server is listening on */
85 86
    hret = margo_addr_self(mid, &addr_self);
    if(hret != HG_SUCCESS)
87
    {
88 89
        fprintf(stderr, "Error: margo_addr_self()\n");
        margo_finalize(mid);
90 91
        return(-1);
    }
92 93
    hret = margo_addr_to_string(mid, addr_self_string, &addr_self_string_sz, addr_self);
    if(hret != HG_SUCCESS)
94
    {
95 96 97
        fprintf(stderr, "Error: margo_addr_to_string()\n");
        margo_addr_free(mid, addr_self);
        margo_finalize(mid);
98 99
        return(-1);
    }
100
    margo_addr_free(mid, addr_self);
101

102
    printf("# accepting RPCs on address \"%s\"\n", addr_self_string);
103 104 105 106 107 108 109

    /* register RPCs and services */
    /***************************************/

    /* register a shutdown RPC as just a generic handler; not part of a
     * multiplexed service
     */
110
    MARGO_REGISTER(mid, "my_shutdown_rpc", void, void, my_rpc_shutdown_ult);
111 112

    handler_pool = margo_get_handler_pool(mid);
Philip Carns's avatar
Philip Carns committed
113 114 115
    svc = strtok(svc_list, ",");
    while(svc)
    {
Philip Carns's avatar
Philip Carns committed
116
        if(!strcmp(svc, "data-xfer"))
Philip Carns's avatar
Philip Carns committed
117 118 119
        {
            data_xfer_service_register(mid, *handler_pool, 0);
        }
Philip Carns's avatar
Philip Carns committed
120
        else if(!strcmp(svc, "delegator"))
Philip Carns's avatar
Philip Carns committed
121
        {
122
            delegator_service_register(mid, *handler_pool, 0);
Philip Carns's avatar
Philip Carns committed
123 124 125
        }
        else
            assert(0);
Philip Carns's avatar
Philip Carns committed
126 127

        svc = strtok(NULL, ",");
Philip Carns's avatar
Philip Carns committed
128
    }
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

    /* shut things down */
    /****************************************/

    /* NOTE: there isn't anything else for the server to do at this point
     * except wait for itself to be shut down.  The
     * margo_wait_for_finalize() call here yields to let Margo drive
     * progress until that happens.
     */
    margo_wait_for_finalize(mid);

    /*  TODO: rethink this; can't touch mid after wait for finalize */
#if 0
    svc1_deregister(mid, *handler_pool, 1);
    svc1_deregister(mid, svc1_pool2, 2);
    svc2_deregister(mid, *handler_pool, 3);
#endif

    return(0);
}