Issue
I have opened a socket via connect
and want to be able to read results blocking and write non-blocking. My current solution is to set the file descriptor to be non-blocking and then select
when I do a read
.
It would be simpler instead to do something like
int sock = socket(...);
connect(sock, ...);
int reader = dup(sock);
int writer = sock;
fcntl(writer, F_SETFL, fcntl(writer, F_GETFL) | O_NONBLOCK);
Does the call to fcntl
cause both reader
and writer
to be non blocking (it sets it on the I/O object) or does fcntl
set non-blocking on the file descriptor?
Solution
If you read the fcntl
man page carefully, you see the status flags are associated with a file description, not a file descriptor. And dup
says the new and old file descriptor refer to the same file description. So accesses to reader
and writer
should both be non-blocking.
Answered By - Nate Eldredge