Originally Posted by
Javed_iqbal
will using select in an indefinite loop serve the purpose?
IMHO, you should avoid blocking on a recv() call unless you know that there is data ready to be read. Thus, yes, select() would help to notify you that there is activity (data to be read, a disconnect, etc) on the socket. It is also helpful in cases where multiple sockets need to be handled.
Your sendall() function could probably be simplified to the following:
Code:
int sendall(int sock, const char* data, int data_length)
{
int bytes_sent = 0;
while (bytes_sent < data_length)
{
int result = send(sock, data + bytes_sent, data_length - bytes_sent, 0);
if (result == -1)
{
if (errno == EAGAIN) continue; // optionally, you may also want to check if errno == EINTR
bytes_sent = -1;
}
bytes_sent += result;
}
return bytes_sent;
}
Bookmarks