Skip to end of metadata
Go to start of metadata

It is possible to attach a monitor to each instance of an asynchronous primitive. By attaching a monitor to an asynchronous primitive it is possible to be notified every time an interesting event occur. Consider, for example, coconut.aio.monitor.SocketMonitor which is used for monitoring events on an AsyncSocket.

By overriding any of these methods and attaching the monitor to an AsyncSocket the runtime will automatically call the method when the corresponding event occurs. For example, the preWrite() method which is called just before the actual write on an AsyncSocket takes place. The data to be written is passed along, so it can be examined or even modified. There is also a corresponding postWrite() method that is called after the write completes. Passing along the number of bytes written, how many attempts the I/O subsystem needed to write all of the data and in the case of failure, any exception that might have occurred.

The following snippet taken from coconut.aio.tools.monitor.debug.DebugSocketMonitor shows how this can be used to get detailed output:

First (in preWrite()) we push the buffers that are to be written. Then we pop them (in postWrite()) and output them using a tool that format byte sequences nicely. The following is a sample from the output of DebugSocketMonitor.

Labels
  • None