X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fnetwork.c;h=0d29637d3f3796ecbcf6120ab50e382fc3c53bb7;hb=c19003f1bac364c5818882616e5deada3b77c3d6;hp=27bc5ed591dd3dc3c7c7abc771306a6d680d3655;hpb=98df3928004ecc6369a5af6e16f1915e170236a2;p=dragonblocks_alpha.git diff --git a/src/network.c b/src/network.c index 27bc5ed..0d29637 100644 --- a/src/network.c +++ b/src/network.c @@ -8,8 +8,8 @@ bool send_command(Client *client, RemoteCommand cmd) return ret; } -static void handle_packets(Client *client) { - while (client->state != CS_DISCONNECTED) { +static bool handle_packets(Client *client) { + while (client->state != CS_DISCONNECTED || ! interrupted) { struct pollfd pfd = { .fd = client->fd, .events = POLLIN, @@ -20,21 +20,20 @@ static void handle_packets(Client *client) { if (pstate == -1) { perror("poll"); - return; + break; } - if (client->state == CS_DISCONNECTED) - return; - - if (pstate == 0) + if (pstate == 0) { + sched_yield(); continue; + } if (! (pfd.revents & POLLIN)) - return; + return false; HostCommand command; if (! read_u32(client->fd, &command)) - return; + break; CommandHandler *handler = NULL; @@ -46,9 +45,11 @@ static void handle_packets(Client *client) { if (! good) printf("Recieved %s command, but client is in invalid state: %d\n", handler->name, client->state); if (! handler->func(client, good)) - return; + break; } else { printf("Recieved invalid command %d\n", command); } } + + return client->state == CS_DISCONNECTED || errno == EINTR; }