Sybase Technical Library - Product Manuals Home
[Search Forms] [Previous Section with Hits] [Next Section with Hits] [Clear Search] Expand Search

Server message callbacks [Table of Contents] Capabilities

Open Client Client-Library/C Reference Manual

[-] Chapter 2 Topics
[-] Callbacks
[-] Signal callbacks

Signal callbacks

A signal callback is called whenever a process receives a signal on a UNIX platform.

On UNIX platforms, Client-Library uses signal-driven I/O to interact with the network. On these platforms, if an application handles signals, it must install the signal handler through Client-Library, even if the signals relate to non-Client-Library work. To install a signal handler, call ct_callback instead of using a system call. A system call to install a signal handler overwrites Client-Library's signal handler. If this occurs, Client-Library's behavior is undefined.

When Client-Library is used in an Open Server gateway, signal handlers should be installed using Server-Library routines.

When Client-Library receives a signal, Client-Library's signal handler:

Defining a signal callback

A signal callback must be defined according to operating system specifications.

An application that defines and installs a signal callback must include the appropriate operating system header file (sys/signal.h on most UNIX platforms).

Installing a signal callback

A signal callback is installed only at the context level.

Signal callbacks are identified by adding the signal number on to the defined constant CS_SIGNAL_CB.

The following routine demonstrates how to install a signal callback:

          /*
           ** INSTALLSIGNALCB
           **
           ** This routine installs a signal callback for the
           ** specified signal
           **
           ** Parameters:
           **      cp   Context handle
           **      signo   Signal number
           **      signalhandler   Signal handler to install
           **
           ** Returns:
           **      CS_SUCCEED   Signal handler was installed
           **                   successfully
           **      CS_FAIL      An error was detected while
           **                   installing the signal handler
           */
           CS_RETCODE  installsignalcb(cp, signo, signalhandler)
           CS_CONTEXT  *cp;
           CS_INT  signo;
           CS_VOID *signalhandler;
           {
                CS_INT       adjustedsigno;
                CS_RETCODE   ret;

               /*
                ** Add the signal number to the CS_SIGNAL_CB 
                ** define to indicate the signal number that this
                ** handler is being installed for.
                */
                adjustedsigno = CS_SIGNAL_CB + signo;

               ret = ct_callback(cp, (CS_CONNECTION *)NULL,
                     CS_SET, adjustedsigno, signalhandler);

               return(ret);
           }


Server message callbacks [Table of Contents] Capabilities