Blocking Sockets

Blocking sockets are especially useful in multithreaded operating systems, in which each socket can be on its own thread. If a network operation takes several seconds, the thread sleeps and the rest of the operating environment continues running unencumbered. When the network operation completes, the socket’s thread wakes up and the network application continues. Blocking sockets are by far the most straightforward approach.

Unfortunately, blocking sockets don’t work very well in single-threaded environments. And the Palm OS is effectively a single tasking operating system; there is only a single thread for all user interface processes. Network applications must be very careful not to tie up this user interface thread. The Palm OS event model requires rapid responses to events. More, smaller steps are better than fewer, bigger steps.

Until now, we have worked with blocking sockets. We first addressed the need for smaller steps by specifying relatively small timeouts to our Net Library function calls. We found that the lowest limit for timeouts was five seconds, which still gives us a rather jerky user experience.

We improved things slightly by introducing NetLibSelect in Chapter 10. This removed the need to timeout on every read operation, but introduced a timeout on each select operation. The lower limit of the timeout used with blocking sockets depends on many factors: the type of connection and connection speed, the responsiveness of the server, latency between ...

Get Palm OS Network Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.