aboutsummaryrefslogtreecommitdiff
path: root/tests/test-rpc_server.c
blob: 9736cc189a5512b6aa7df7cb04005b1f2afa872f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <hal.h>

#define interrupt 0

static uint8_t inbuf[HAL_RPC_MAX_PKT_SIZE], outbuf[HAL_RPC_MAX_PKT_SIZE];

static void hal_rpc_server_main(void)
{
    size_t ilen, olen;
    void *opaque;
    hal_error_t ret;

    while (!interrupt) {
        ilen = sizeof(inbuf);
        ret = hal_rpc_recvfrom(inbuf, &ilen, &opaque);
        if (ret == HAL_OK) {
            olen = sizeof(outbuf);
            if (hal_rpc_server_dispatch(inbuf, ilen, outbuf, &olen) == HAL_OK)
                hal_rpc_sendto(outbuf, olen, opaque);
        }
    }
}

int main (int argc, char *argv[])
{
    if (hal_rpc_server_init() != HAL_OK)
	return 1;

    hal_rpc_server_main();
    hal_rpc_server_close();
    return 0;
}