dbsetinterrupt

Description

Calls user-supplied functions to handle interrupts while waiting on a read from the server.

Syntax

void dbsetinterrupt(dbproc, chkintr, hndlintr)
 
DBPROCESS    *dbproc;
int                      (*chkintr)();
int                      (*hndlintr)();

Parameters

dbproc

A pointer to the DBPROCESS structure that provides the connection for a particular front-end/server process. It contains all the information that DB-Library uses to manage communications and data between the front end and server.

chkintr

A pointer to the user function that DB-Library calls to check whether an interrupt is pending. DB-Library calls it periodically while waiting on a read from the server. DB-Library calls chkintr() with a single parameter—a pointer to the DBPROCESS from the dbsetinterrupt call.

chkintr() must return “TRUE” or “FALSE”.

hndlintr

A pointer to the user function that DB-Library calls if an interrupt is returned. DB-Library calls hndlintr() with a single parameter—a pointer to the DBPROCESS from the dbsetinterrupt call.

Table 2-27 lists the legal return values of hndlintr:

Table 2-27: Return values for the hndlintr() function

Return value

To indicate

INT_EXIT

Abort the program. (Note to UNIX programmers: DB-Library will not leave a core file.

INT_CANCEL

Abort the current command batch. Results are not flushed from the DBPROCESS connection.

INT_CONTINUE

Continue to wait for the server response.

Returns

None.

Usage


Canceling from the interrupt handler


Example

int CS_PUBLIC  chkintr(dbproc) 
DBPROCESS      *dbproc; 
 { 
   /* 
   ** This routine assumes that the application 
   ** sets the global variable
   ** "OS_interrupt_happened" upon catching 
   ** an interrupt using some operating system
   ** facility. 
   */ 
   if (OS_interrupt_happened) 
   { 
     /* 
     ** Clear the interrupt flag, for 
     ** future use. 
     */ 
     OS_interrupt_happened = FALSE; 
     return(TRUE); 
   } 
   else 
     return(FALSE); 
 } 

int CS_PUBLIC  hndlintr(dbproc) 
 DBPROCESS      *dbproc; 
 { 
   char    response[10]; 
   DBBOOL *int_canceled;
   /*
   ** We assume that a DBBOOL flag has been
   ** attached to dbproc with dbsetuserdata.
   */
   int_canceled = (DBBOOL *) dbgetuserdata(dbproc);
   if (int_canceled == (DBBOOL *)NULL)
   {
     printf(“Fatal Error: no int_cancel flag \
           in the DBPROCESS\n”);
     return(INT_EXIT);
   }
   *int_canceled = FALSE;
   printf("\nAn interrupt has occurred. Do you \
         want to:\n\n"); 
   printf("\t1) Abort the program\n"); 
   printf("\t2) Cancel the current query\n"); 
   printf("\t3) Continue processing the current\
         query’s results\n\n"); 
   printf("Press 1, 2, or 3, followed by the \ 
         return key: "); 
   gets(response); 
   switch(response[0]) 
   { 
     case ’1’: 
       return(INT_EXIT); 
       break; 
     case ’2’: 
       *int_canceled = TRUE;
       return(INT_CANCEL); 
       break; 
     case ’3’: 
       return(INT_CONTINUE); 
       break; 
     default: 
       printf("Response not understood. \ 
             Aborting program.\n"); 
       return(INT_EXIT); 
       break; 
   } 
 }

See also

dbcancel, dbgetuserdata, dbsetuserdata, dbsetbusy, dbsetidle