Hi. Im working on a project with a relative size and Ive run into a deadlock, I need some advice in how to proceed.
I have a server that creates multiple threads to handle its clients, but each thread must serve a client multiple times,
here is the thread handling function:
void *handle_client (void *socket){
struct message_t *message;
int novoSock = *(int *) socket;
while(1){
message = malloc(sizeof(struct message_t));
message = network_to_message(novoSock);
if(invoke(message) == 0){
message_to_network(message, novoSock);
close(novoSock);
}
else{
printf("invoke failure\n");
close(novoSock);
}
free(message);
}
return NULL;
}
Problem is that after doing the while once I need the thread to wait for a new message to reach the socket,
but how can I do that with a persistent connection? How do I know when to get the message coming from the client? Anyone with any ideas?