I have an asynchronous application executing several threads doing operations over sockets where operations are scheduled and then executed asynchronously.
I'm trying to avoid a situation when once scheduled a read operation over a socket, the socket gets closed and reopened(by possibly another peer in another operation), before the first operation started execution, which will end up reading the proper file descriptor but the wrong peer.
The problem comes because (accept();close();accept()) returns the same fd in both accepts() which can lead to the above situation.
I can't see a way of avoiding it.
any hint?