FTAM/9000 Programmer's Guide

186 Chapter 4
Using Support Functions
Responding to Asynchronous Calls
The following program example illustrates how to use em_hp_select()
and an HP–UX pipe to implement the signal handling technique
described previously.
#include %<signal.h>
#include %</opt/ftam/include/map.h>
#define BITS_PER_INT 32
#define SET_MASK(f,fds) (fds)[((f)/BITS_PER_INT)] |=
(1%<%<((f)%BITS_PER_INT))
#define TST_MASK(f,fds) ((fds)[((f)/BITS_PER_INT)] &
(1%<%<((f)%BITS_PER_INT)))
#define READ 0
#define WRITE 1
int sig_pipe[2]; /* Pipe r/w descriptors used to queue signals */
void
signal_handler(sigval)
int sigval;
{
/* Put signal on the pipe to make the pipe readable. This will cause
** em_hp_select() to return.
*/
write(sig_pipe[WRITE], & sigval, sizeof(int));
/* Perform other signal handling logic if any. */
}
main()
{
int sigval; /* The signal value read from pipe */
struct sigvec vec; /* sigvector for installing handler */
Local_event_name map_event; /* MAP Event Name */
Return_code map_rc; /* MAP return code */
Api_rc map_result; /* MAP result structure */
int nfds; /* File descriptor bound */
unsigned readfds[2]; /* File descriptor mask */
/*
** Create the HP-UX pipe which is used to translate the signal interrupt
** into an em_hp_select() non-MAP event.
*/
pipe (sig_pipe);