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,
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;
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;
}