If I got a file descriptor (socket fd), how to check this fd is avaiable for read/write?
In my situation, the client has connected to server and we know the fd.
However, the server will disconnect the socket, are there any clues to check it ?
If I got a file descriptor (socket fd), how to check this fd is
Share
You want
fcntl()to check for read/write settings on the fd:But this is a separate issue from when the socket is no longer connected. If you are already using
select()orpoll()then you’re almost there.poll()will return status nicely if you specifyPOLLERRineventsand check for it inrevents.If you’re doing normal blocking I/O then just handle the read/write errors as they come in and recover gracefully.