Variations

The demux can interface to the dispatcher in many ways. Depending on how the handles and demux are implemented, the demux may require handles to be registered in advance or provided as a parameter to select (as in the POSIX select(2) function). One simple way to report events is to have the select method return one of the received events. POSIX select(2) outputs a bitmask showing which handles have unprocessed events; the handles are then read as usual (e.g. with read(2)). This allows multiple events to be handled per select call at the expense of a more complex interface.

Events of different types may be separated by the demux and different handlers assigned for different event types on the same handle. This complicates the Reactor somewhat, and it is usually easier (albeit less efficient if the handles generate many events of a type that one wishes to ignore) to separate different event types within the event handlers.

The Reactor can also be used to prevent outgoing communication from blocking, which may become a problem if handling an event involves a long blocking output operation (e.g. sending a file larger than the network buffers to a remote machine). In this case, a handle that sends events indicating that a socket can be written to may be useful in ensuring that one slow client cannot impede the other clients.

Jan Lönnberg 2006-10-23