However we slice it, our application is eventually going to timeout on network operations. And while it waits for this timeout, the rest of the user interface will come to a complete halt. The user can select controls, push hardware buttons, turn the device on and off, i.e., do just about anything. The device ignores them; to the casual observer, the device seems dead for a few seconds. It’s not a satisfying user experience to have the device go dead for a couple of seconds.
The solution is nonblocking sockets. In Chapter 6, we discuss the architectural division between the Palm OS Net Library and the TCP/IP protocol stack. When we look at any network operation, there are two stages to it. There is the stage during which the TCP stack handles the connection semantics, storing inbound data into buffers, sending outbound data from buffers, and making and accepting connection requests. There is also the Net Library function stage, where the results of these network operations are returned to the application.
Since then, we have paid little attention to this division. With blocking sockets, these phases are tightly coupled. Net library function calls initiated network operations and waited for them to complete before returning.
Nonblocking sockets fit well with the division between Net Library functions and the protocol stack’s network operations. Net Library functions simply check the state of a network operation. If an operation does not return immediately, the ...