I am using the preforking concept.
When I establish a socket in the server, the file descriptor value returned is 7. I know that it will allocate a available number for the file descriptor.
When I made the same child process to accept for new connections on the same socket, It wont accept()
the connection.
But when I reset the value of file descriptor to 7, then It starts accepting the connections.
I am not finding the reason behind it. Can anyone through some light on this.
My code looks similar to this
for (;;)
{
int session_fd=accept(server_fd,0,0);
if (session_fd==-1)
{
if (errno==EINTR) continue;
die("failed to accept connection (errno=%d)",errno);
}
handle_session(session_fd);
close(session_fd);
server_fd = 7;
}