Blocking vs. Non-blocking Mode
Berkeley sockets can operate in one of two modes: blocking or non-blocking.
A blocking socket will not return control until it has sent (or received) some or all data specified for the operation. It is normal for a blocking socket not to send all data. The application must check the return value to determine how many bytes have been sent or received and it must resend any data not already processed. It also may cause problems if a socket continues to listen: a program may hang as the socket waits for data that may never arrive. When using blocking sockets, special consideration should be given to accept as it may still block after indicating readability if a client disconnects during the connection phase.
On the other hand, a non-blocking socket will return whatever is in the receive buffer and immediately continue. If not written correctly, programs using non-blocking sockets are particularly susceptible to race conditions due to variances in network link speed.
A socket is typically set to blocking or nonblocking mode using the fcntl
or ioctl
functions.
Read more about this topic: AF INET
Famous quotes containing the words blocking and/or mode:
“Cassoulet, that best of bean feasts, is everyday fare for a peasant but ambrosia for a gastronome, though its ideal consumer is a 300-pound blocking back who has been splitting firewood nonstop for the last twelve hours on a subzero day in Manitoba.”
—Julia Child (b. 1912)
“The mode of clearing and planting is to fell the trees, and burn once what will burn, then cut them up into suitable lengths, roll into heaps, and burn again; then, with a hoe, plant potatoes where you can come at the ground between the stumps and charred logs; for a first crop the ashes suffice for manure, and no hoeing being necessary the first year. In the fall, cut, roll, and burn again, and so on, till the land is cleared; and soon it is ready for grain, and to be laid down.”
—Henry David Thoreau (18171862)