On my TCP server I would like to have:
non-blocking passive socket to have non-blocking accept();
after accepting connection I would like to perform some authentication like verifying client provided Id and Password. So I have well defined protocol and I would like to have blocking recv()/send() talk between TCP server and client via connection socket.
After client identity verification I would like to have non-blocking connection socket to enable server shutdown from external thread.
The problem is that when I firstly set non-blocking PASSIVE socket then accepted CONNECTION sockets are also non-blocking? Why aren't they separate sockets?
I have set passive socket to non-blocking mode using this code:
fcntl(ps_fd, F_SETFL, O_NONBLOCK);
I do authentication through connection socket:
if((n_recv = recv(sock_fd, buf, sizeof(buf) - 1, 0)) <= 0) { ... }
But here recv()
doesn't block and client cannot deliver it's authentication id and password on the time before EAGAIN
error.
Can I revert connection socket to be in blocking mode again, and passive socket left non-blocking?