I have implemented a client that talks to another server. Both exchange messages using a TCP/IP socket.
I notice that each time the server sends me a message i get the following perror "No such file or directory" on my select call. Whats strange is that the correct bit is set and i am able to read the message from the server, but its annoying to see this error.
The reason i had the retry_interval is in case i lose a connection with the server. In that case i set the retry_interval and i keep retrying forming a session again.
Relevant code from the client on which i see this error message:
for (;;)
{
program_select_to_look_at_right_sockets(&readfds, &maxfds);
do
{
if (RETRY_TIMER_IS_SET(retry_interval))
{
activity = select( maxfds + 1 , &readfds , NULL , NULL , &retry_interval);
set_retry_timer (&retry_interval);
}
else
activity = select( maxfds + 1 , &readfds , NULL , NULL , NULL);
perror("main loop select error"); <-- Whenever i get a message from server this select throws an error
} while (activity < 0 && errno == EINTR);
if (RETRY_TIMER_IS_SET(retry_interval))
{
printf ("Connect RETRY timer to server expired!\n");
connect_to_server_again();
}
else if (FD_ISSET (server_connection_socket, &readfds))
{
/* Even if an error is thrown the code does reach this point which i find somewhat strange */
printf ("Server sent us a message!\n");
bytes_read = process_data_from_server();
if (bytes_read == 0)
{
clean_connection_from_server (&readfds);
set_retry_timer (&retry_interval);
}
}
Why do you think select
is returning that error? You need to check select
's return code to see if there was an error. More information is here:
http://man7.org/linux/man-pages/man2/select.2.html
If you don't check the return code then you don't know if there was an error, and the error printed by perror could be some random thing from a previous function call.