Answer Posted / chaitanya
Technically, fcntl(soc, F_SETFL, O_NONBLOCK) is incorrect since it clobbers all other file flags. Generally one gets away with it since the other flags (O_APPEND for example) don't really apply much to sockets. In a similarly rough vein, you would use fcntl(soc, F_SETFL, 0) to go back to blocking mode.
To do it right, use F_GETFL to get the current flags, set or clear the O_NONBLOCK flag, then use F_SETFL to set the flags.
And yes, the flag can be changed either way at will.
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Is a socket a file?
Can multiple clients connect to same socket?
How does unix socket work?
Is tcp or unix socket faster?
What's the difference between impact sockets and regular sockets?
How can I set the timeout for the connect() system call?
Why sockets are used?
What is socket address with example?
What is a socket connection?
Why do we need sockets?
How many sockets can a port have?
How many socket connections can a server handle?
Can a single socket port be used for multiple applications?
Are unix sockets faster than tcp?
What is the difference between SO_REUSEADDR and SO_REUSEPORT?