Link to home
Start Free TrialLog in
Avatar of tryonix
tryonix

asked on

are linux sockets blocking by default

hi everybody,

i am writing a socket class in linux

i am using write and read to write and read from my socket

i have searched for information on whether a socket is blocking by default.
all i can find is that to make a socket nonblocking set the O_NONBLOCK fllag.

so i am assuming that my read on the socket will block by default.

i need to be sure .

can someone tell me is my read on the socke blocking by default

thank you


ASKER CERTIFIED SOLUTION
Avatar of ravenscr98
ravenscr98

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Alf666
Alf666

I confirm. Sockets are blocking. Hence the two calls (one system V and the other one BSD origins) :

- select
- poll

Both these calls allow you to set-up a loop in which you will be waiting for data on a set of sockets (file descriptors in fact).
When returning, they will give you the list of sockets ready for reading, writing, or the ones with pending exceptions.

Using this mechanism, you will be able to handle data only on sockets that  will allow you to act without blocking.

man select

Avatar of sunnycoder
I third that ... Linux sockets are blocking by default
Avatar of tryonix

ASKER

raven answered first so the points go to him.

thanks guys