Examples on how to code the client to use timeouts 1. Code the client to wait only a set period of time. There are 2 main ways that client code can be written to wait only a set period of time before taking alternative action: i. Set a timeout before any call to the database and generate a break / interrupt signal if this timeout expires. Eg: Use an Oracle8 OCIBreak() or ii. Use non-blocking OCI and monitor a timer whilst polling for a response. If the timer expires issue an OCIBreak() i. Setting a timeout OCIBreak() sends a TCP packet to the server and so should cause an error on the local socket if that packet cannot be delivered. Eg: The following code shows an example of timing out a statement on a Unix client. MyAlarm() { printf("sending break\n"); printf("OCIBreak=%d\n",OCIBreak( (dvoid *)svchp, (OCIError *)errhp)); printf("break sent\n"); return; } ... { void * osig; ... /* -- Install an alarm signal handler -- */ osig=signal( SIGALRM, MyAlarm ); /* -- Set a timeout for 90 seconds -- */ alarm(90); /* -- Run the statement - could hang if server dies --*/ printf("Calling execute\n"); if ((status = OCIStmtExecute(svchp, stmthp, errhp, (ub4) 1, (ub4) 0, (CONST OCISnapshot *) NULL, (OCISnapshot *) NULL, OCI_DEFAULT)) && status != 1) { /* -- Disable the timer -- */ alarm(0); checkerr(errhp, status); return OCI_ERROR; } printf("All done\n"); /* -- Disable the timer in case it did not go off -- */ alarm(0); /* -- Put back any old signal handling for an alarm -- */ signal( SIGALRM, osig ); .... } ii. Non-blocking OCI In non-blocking mode OCI calls return ORA-3123 if the call is still waiting for the server. As the OCI functions do not block in this mode it is possible to issue OCIBreak() if no response is received after a reasonable timeout. You may need to keep calling OCI functions after this until an error is received on the connection for non-delivery of the TCP packet. A combination of these 2 approaches may be the best option such as using non-blocking mode along with 'ognfd()' and a 'select()' statement. This allows client code to wait for a response for a preset period of time without wasting CPU. If a response is received this can be processed otherwise the timer will expire and OCIBreak() can be sent. Eg: Example of obtaining the file handle using ognfd() and monitoring it with "select()". (Error handling skipped for readability) Lda_Def lda; /* An OCI7 LDA for temporary use */ int fd; /* File handle SOCKET */ fd_set maset; /* File descriptors to monitor */ fd_set fdSet; /* File descriptors with events pending */ struct timeval timer; /* Timeout */ timer.tv_sec=300; /* 5 minute timeout */ timer.tv_usec=0; ... OCIServerAttach( ... ) /* or OCILogon() */ OCISessionBegin( ... ) ... OCISvcCtxToLda( svchp, errhp, &lda ); /* Convert to V7 LDA */ ognfd(&lda,&fd); /* Get socket handle */ OCILdaToSvcCtx( &svchp, errhp, &lda ); /* Back to V8 */ FD_ZERO(&maet); /* ZERO handles to monitor */ FD_SET(fd,&maset); /* Save the file handle */ fdSet=maset; /* Set handles to monitor */ do { if (FD_ISSET(fd,&fdSet) { /* 1st time queue an OCI request, 2nd time poll for result */ ... non blocking OCI call goes here ... ... Process errors , but fall through on ORA-3123 to the select ... ... On success move on to the next OCI statement ... } fdset=maset; /* Set handles to monitor */ printf( "Waiting for an event ... \n"); } while (select(maxfd,&fdSet,0,0,&timer)