You want to fcntl()check read / write settings on fd:
#include <unistd.h>
#include <fcntl.h>
int r;
r = fcntl(fd, F_GETFL);
if (r == -1)
if (r & O_RDONLY)
else if (r & O_WRONLY)
else if (r & O_RDWR)
But this is a separate issue when the socket is no longer connected. If you are already using select()or poll(), then you are almost there. poll()will return the status beautifully if you point POLLERRin eventsand check it in revents.
-, / .