3 bool send_command(Client *client, RemoteCommand cmd)
5 pthread_mutex_lock(&client->mtx);
6 bool ret = write_u32(client->fd, cmd);
7 pthread_mutex_unlock(&client->mtx);
11 static bool handle_packets(Client *client) {
12 while (client->state != CS_DISCONNECTED || ! interrupted) {
19 int pstate = poll(&pfd, 1, 0);
31 if (! (pfd.revents & POLLIN))
35 if (! read_u32(client->fd, &command))
38 CommandHandler *handler = NULL;
40 if (command < HOST_COMMAND_COUNT)
41 handler = &command_handlers[command];
43 if (handler && handler->func) {
44 bool good = client->state & handler->state_flags;
46 printf("Received %s command, but client is in invalid state: %d\n", handler->name, client->state);
47 if (! handler->func(client, good))
50 printf("Received invalid command %d\n", command);
54 return client->state == CS_DISCONNECTED || errno == EINTR;