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

#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <abt.h>
Philip Carns's avatar
Philip Carns committed
11 12
#include <abt-snoozer.h>
#include <margo.h>
13 14 15 16 17 18 19 20 21 22 23

#include "my-rpc.h"

/* example server program.  Starts HG engine, registers the example RPC type,
 * and then executes indefinitely.
 */

int main(int argc, char **argv) 
{
    int ret;
    ABT_eventual eventual;
24
    int *shutdown;
25
    margo_instance_id mid;
26 27 28 29 30 31 32 33
    
    ret = ABT_init(argc, argv);
    if(ret != 0)
    {
        fprintf(stderr, "Error: ABT_init()\n");
        return(-1);
    }

Philip Carns's avatar
Philip Carns committed
34 35
    /* set primary ES to idle without polling */
    ret = ABT_snoozer_xstream_self_set();
36 37
    if(ret != 0)
    {
Philip Carns's avatar
Philip Carns committed
38
        fprintf(stderr, "Error: ABT_snoozer_xstream_self_set()\n");
39 40 41
        return(-1);
    }

42
    mid = margo_init(NA_TRUE, "tcp://localhost:1234");
43 44

    /* register RPC */
45
    my_rpc_register(mid);
46 47

    /* suspend this ULT until someone tells us to shut down */
48
    ret = ABT_eventual_create(sizeof(*shutdown), &eventual);
49 50 51 52 53 54 55 56
    if(ret != 0)
    {
        fprintf(stderr, "Error: ABT_eventual_create()\n");
        return(-1);
    }

    ABT_eventual_wait(eventual, (void**)&shutdown);

57
    margo_finalize(mid);
58 59 60 61 62
    ABT_finalize();

    return(0);
}