From fc517f9113b012a9872dcb7938846bcc94a5fd4d Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Sat, 5 May 2018 23:36:10 +0300 Subject: server: separate networking code into its own thread[s]. --- src/server/main.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/server/main.c') diff --git a/src/server/main.c b/src/server/main.c index 5c0628a..f4d9fdc 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -33,22 +33,26 @@ #include #include "net.h" -static struct netstate *init(const unsigned int port); +int init(const unsigned short int port); static void draw_idle(void); static void draw_busy(const char * const data); static float digest_temp(const short int rawdata); int main(void) { - struct netstate *state; - char data[32] = {0}; + static const struct timespec wait = {0, 200 * 1000 * 1000}; /* 200 ms */ + char data[dgsize] = {0}; int status; - struct timespec wait = {0, 100 * 1000 * 1000}; + int nd; - state = init(2191); + nd = init(2191); + + if (nd == NET_ERROR) { + goto fail; + } do { - status = state->getlastdata(data, state); + status = net_getlastdata(nd, data); switch (status) { case NET_OK: /*fall-through */ @@ -65,15 +69,15 @@ int main(void) } while (getch() != 'q'); fail: - net_close(&state); + net_close(nd); endwin(); return 0; } -static struct netstate *init(const unsigned int port) +int init(const unsigned short int port) { - struct netstate *ret; + int ret; ret = net_init(port); initscr(); -- cgit v1.2.3