I am using recv
to receive a message on the socket from the server.
size_t b_received = 0;
char headers[2048];
while ((b_received = recv(socket_fd,
&headers[pos],
sizeof(headers) - pos - 1, 0)) > 0) {
pos += b_received;
}
Sometimes, the server takes too long to send a message and my program is stuck and waiting for the next message.
Is there a way I could just end this loop if the server does not send me the next message after 5 seconds?