Open System Services Programmer's Guide

OSS File Descriptor and Timer Callbacks
Thread-aware functions listed in Table 64 allow registration and use of callbacks for OSS file
descriptors and timer callbacks. For details on each function, see the appropriate reference page
in the Open System Services System Calls Reference Manual.
Table 64 Thread-Aware Callback Functions and Types
DescriptionFunction
Callback type required by spt_regOSSFileIOHandler().spt_OSSFileIOHandler_p
Register the file descriptor as one that the user will manage through a user
supplied callback.
spt_regOSSFileIOHandler
Unregister file descriptor as one that the user will manage.spt_unregOSSFileIOHandler
Set interest in file descriptor.spt_setOSSFileIOHandler
Register a user supplied timer callback.spt_regTimerHandler
Callback type required by spt_regTimerHandler().spt_TimerHandler_p
Using OSS and Timer Callbacks
Example 84 shows an OSS file descriptor callback program flow. Typically, the callback would
conditionally signal a thread that the file descriptor is read-ready.
Example 84 OSS File Descriptor Callback
...
spt_regOSSFileIOHandler(fd, callback);
spt_setOSSFileIOHandler(fd, 1, 0, 0); // Only interested in read ready.
...
// Do work on file descriptor via user supplied callback.
...
spt_unregOSSFileIOHandler(fd);
...
Example 85 shows an OSS timer callback program flow. As soon as possible, the pthreads
scheduler initially invokes the timer callback, with successive invocations of the callback driven by
the callback’s return value. For more information, see the spt_TimerHandler_p(2) reference
page.
Example 85 Timer Callback Program Flow
...
spt_regTimerHandler(callback);
...
Caveat to Using Callbacks
An OSS field descriptor callback takes precedent over all other operations that are waiting on the
file descriptor. For example, if a thread is blocked on spt_fd_read_ready() and there is a
callback registered for that particular file descriptor, the thread will never be awakened by the file
descriptor being read-ready, even if the callback didn’t set interest in read-ready.
Timer callbacks must not block and may be invoked sooner or later than requested.
OSS File Descriptor and Timer Callbacks 379