Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The most obvious result of switching our sockets to nonblocking is significantly improved performance. With blocking sockets, we specified timeouts of five seconds. This meant that if a function were going to fail because the network operation did not complete in time, it would take five seconds.
With nonblocking sockets, these function calls fail immediately. Thus we finish our receive loops faster—the last iteration of the loop that would previously block until the timeout expired now immediately returns an error. This saves us five seconds every time a receive operation fails because there's no data to receive.