Chapter 10. Reading and Writing Responsively
The Zen of Palm demands that applications respond quickly to user
input. Chapter 9’s version of
FtpView
falls short of this ideal. Press the
Login
button and the device seems to hang. If you
are patient, you might wait long enough for the application to finish
what its doing and return to life. Hardly Zen.
The Palm OS provides a single-thread execution environment; applications share this thread by cooperative multitasking. Monopolizing the processor while you wait for incoming networking messages is a bad approach to cooperative multiprocessing. We need to fix this.
In this chapter, we convert our application to use an event-driven networking architecture. In an event-driven architecture, the application waits for events to happen, and responds to these events when they happen. We introduce socket multiplexing and how it enables our event-driven network architecture. We split our FTP login and logout processes so that they are handled over a series of events.
Deconstructing FtpView
There are two basic problems with our application. First, we perform the entire login or logout process while handling a single event. This stops the application thread while we wait to send commands and receive responses, especially the responses.
Sending FTP commands is not the problem. We know how many we are sending and how long each is. We know when we are done sending them. Since these commands are short, they are generally sent in one try. And it is ...
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.