5.2.3 System-Supplied Services: tpsvrdone( ) Function
The tpsvrdone()
function calls
tpclose()
to close the resource manager, similarly to
the way tpsvrinit()
calls tpopen()
to
open it.
Note:
If writing a multithreaded server, you must use thetpsvrthrdone()
command to open a resource manager, as described in Programming a Multithreaded and Multicontexted ATMI Application.
Use the following signature to call the tpsvrdone()
function:
void
tpsvrdone() /* Server termination routine */
The tpsvrdone()
function requires no arguments.
If an application does not define a closing routine for
tpsvrdone()
, the Oracle Tuxedo system calls the
default routine supplied by main()
. This routine calls
tx_close()
and
userlog()
to close the resource manager
and write to the central event log, respectively. The message sent
to the log indicates that the server is about to exit.
tpsvrdone()
is called after the server has finished processing service requests but before it exits. Because the server is still part of the system, further communication and transactions can take place within the routine, as long as certain rules are followed. These rules are covered in Managing Errors.
The following listing illustrates how to use the
tpsvrdone()
function to close a resource manager and
exit gracefully.
Listing Closing a Resource Manager with tpsvrdone( )
void
tpsvrdone()
{
/* Close the database */
if(tpclose() == -1)
(void)userlog("tpsvrdone: failed to close database: ");
switch (tperrno) {
case TPESYSTEM:
(void)userlog("ORACLE TUXEDO error\n");
break;
case TPEOS:
(void)userlog("Unix error %d\n",Uunixerr);
break;
case TPEPROTO:
(void)userlog("Called in improper context\n");
break;
case TPERMERR:
(void)userlog("RM failure\n");
break;
}
return;
}
return;
}
Parent topic: System-Supplied Server and Services