TipcConnKeepAlive


Name

TipcConnKeepAlive — check if the process at the other end of a connection is still alive

Synopsis

T_BOOL TipcConnKeepAlive(conn) 
T_IPC_CONN conn; 

Arguments

conn — connection to initiate keep alive on

Return Values

TRUE if the other end of the connection responded in time, FALSE otherwise.

Diagnostics

If TipcConnKeepAlive fails, it returns FALSE and sets the global SmartSockets error number to one of:

Description

TipcConnKeepAlive performs a remote procedure call to check if the process at the other end of a connection is still alive. This explicit attempt to check the health of a connection is called a keep alive. TipcConnKeepAlive is normally used only by TipcConnCheck, which automatically checks the connection based on the read timeout property of the connection. TipcConnKeepAlive can be called explicitly, though, to check the health of the connection.

TipcConnKeepAlive performs these steps:

  1. Temporarily sets the read timeout of the connection to 0. This is necessary to prevent recursive calls to TipcConnKeepAlive when the result message is being waited for.
  1. Creates a KEEP_ALIVE_CALL message.
  2. Sends the KEEP_ALIVE_CALL message with TipcConnMsgSend.
  3. Flushes the message with TipcConnFlush.
  4. Searches for KEEP_ALIVE_CALL and KEEP_ALIVE_RESULT messages with TipcConnMsgSearch. Any KEEP_ALIVE_CALL messages are processed with TipcConnMsgProcess immediately so that mutual keep alives from both ends of a connection are handled quickly. The search ends when the timeout period is reached or a KEEP_ALIVE_RESULT message is found.
  5. Restores the read timeout of the connection and destroys the KEEP_ALIVE_CALL message.

If the other end of the connection is alive, it receives the KEEP_ALIVE_CALL message, processes it with TipcCbConnProcessKeepAliveCall, and sends a KEEP_ALIVE_RESULT message back to this end.

Caution

If keep alives are used for non-RTserver connections, care must be taken to read and process messages at a regular interval. Otherwise the keep alives fail.

See Also

TipcCbConnProcessKeepAliveCall, TipcConnGetTimeout, TipcConnSetTimeout, TipcConnMsgSendRpc

Examples

This example shows a simple way to check the health of a connection every 10 seconds:

/* enable keep alives by setting the keep alive timeout to a non-zero value */ 
if (!TipcConnSetTimeout(conn, T_IPC_TIMEOUT_KEEP_ALIVE, 5.0)) { 
  return;  /* error */ 
} 
 
for (;;) { 
  if (!TipcConnKeepAlive(conn)) { 
    return;  /* error */ 
  } 
  TutSleep(10.0); 
}  

Because TipcConnCheck automatically calls TipcConnKeepAlive when checking for reading, the above fragment could be rewritten as:

/* enable keep alives by setting the keep alive timeout to a non-zero value */ 
if (!TipcConnSetTimeout(conn, T_IPC_TIMEOUT_KEEP_ALIVE, 5.0)) { 
  return;  /* error */ 
} 
 
/* enable read timeout checking by setting the read timeout to a non-zero value */ 
if (!TipcConnSetTimeout(conn, T_IPC_TIMEOUT_READ, 10.0)) { 
  return;  /* error */ 
} 
 
/* based on the above timeout settings, TipcConnCheck will initiate a keep alive every 10 seconds 
and wait for up to 5 seconds for the keep alive to complete */ 
if (!TipcConnCheck(conn, T_IO_CHECK_READ, T_TIMEOUT_FOREVER)) { 
  return;  /* error */ 
} 

TIBCO SmartSockets™ Application Programming Interface
Software Release 6.8, July 2006
Copyright © TIBCO Software Inc. All rights reserved
www.tibco.com