HP X.25/9000 Programmer's Guide
Chapter 5 71
Receiving and Transmitting Out-of-band Information
Building a Signal Handler
Building a Signal Handler
A signal handler is a routine that is called when a signal arrives. The
signal handler executes in the process address space, and all global data
items are available to the signal handler. The process is halted while the
signal handler executes. When the signal handler returns, the process
resumes execution at the point where it was halted.
A signal handler should carry out the following four steps each time it is
executed:
Step 1. Get the cause for the signal being sent.
To get the out-of-band event that caused the signal handler to be
executed in the first place, use the recv() system call with the
MSG_OOB
flag set. recv(MSG_OOB) returns a buffer. The first byte in the buffer
contains the number of bytes in the event (range: 3 to 34 bytes). The
second byte contains the event code (described below), and the rest of the
buffer contains the event data, if any.
The recv(MSG_OOB) call is nonblocking. If the recv() call returns 0,
then no out-of-band events were queued. If the call returns a negative
value, an error occurred. A value greater than 0 indicates the size of the
buffer being returned.
Step 2. Process the event which caused the signal to be sent.
After the cause of the event has been received, the signal handler should
process the event. Usually out-of-band events have an effect on the state
of the VC. For example, the arrival of a CLEAR INDICATION packet
makes the VC unusable. This information should be made known to the
main program. Typically, this is done with globally-defined state
variables. The state variables can be tested by the main program, or
examined only after a system call returns with an error. Many of the
state changes of a VC are made known to the process through
errno
when a system call is executed.
The actual strategy used to pass information to the main program is up
to the application designer.
Possible out-of-band events and the appropriate actions for each are
described below.
36960-90061.bk Page 71 Friday, November 10, 2000 3:42 PM










