Question

I'm learning to write non-blocking server and client applications using epoll, poll, etc. and came across this event flag:

POLLOUT: Writing now will not block.

I understand the concept of blocking reads. But what are blocking writes?

Was it helpful?

Solution

In any I/O operation the potential to need a trip to the hard disk (or other slow I/O device) and back exists. A "blocking" call is simply one that waits while the round-trip I/O is being done -- in the mean time, your . So, just like you can wait for reading to be done, so can you wait for writing.

This isn't usually so useful for conventional applications -- you want to tell the OS to write your data and then it's not your problem anymore. It becomes your problem when you're trying to guarantee data integrity stored on the I/O device (e.g. hard disk) such as in a relational database system. (Note that blocking isn't the only method by which you can guarantee your writes have been done, however. Also note with the growing complexity of computers, there's multiple layers of caching which may or may not interfere with actual blocking.)

OTHER TIPS

If you are writing to a device like a pipe, socket or terminal at a faster rate than the other side is reading, eventually you will fill up the relevent kernel buffer and subsequent writes will block until some data is read by the other side.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top