Navigation:  Programming Cookbook > Sockets Connectivity > The Socket Connection Interface >


Previous pageReturn to chapter overviewNext page

Many of the standard function calls in the WSockLibrary will block the operating system thread on which they are executing until an operation completes.  Dolphin Smalltalk does not use native operating system threads. Therefore the use of such thread blocking calls is, to say the least, somewhat inconvenient since they will hang up the entire user interface for the duration of the call. Fortunately, Microsoft has provided a number of asynchronous equivalents to these functions (usually with a WSA prefix) which allows the current thread to continue while the operation takes place. The caller is then notified by means of a Windows message when the function call completes its business.

Dolphin supports multiple Smalltalk processes for multitasking purposes but, in fact, these execute on a single operating system thread (apart from garbage collection and finalization). The Sockets Connection package makes extensive use of these asynchronous WSA calls to avoid blocking the Dolphin main thread but to allow the higher level calls to be able to block a Smalltalk process on a Semaphore.

Implementation note: the WinAsyncSocket subclass of View is used to handle the callbacks from the WSAxxx function calls. It has a singleton instance whose job it is to intercept the Windows notification messages and to redirect them to the appropriate Socket that made call. The handlers for these notifications are the #onAsyncXXX methods in SocketAbstract and its subclasses.

The result is that, to all intents and purposes, Sockets Connection is able to provide blocking socket operations in Dolphin.