ct_close

Description

Close a server connection.

Syntax

CS_RETCODE ct_close(connection, option)
 
 CS_CONNECTION     *connection;
 CS_INT                        option;

Parameters

connection

A pointer to a CS_CONNECTION structure. A CS_CONNECTION structure contains information about a particular client/server connection.

option

The option to use for the close. The following table lists the symbolic values for option:

Value of option

Meaning

CS_UNUSED

(10.0+ servers only)

Default behavior.

ct_close sends a logout message to the server and reads the response to this message before closing the connection.

If the connection has results pending, ct_close returns CS_FAIL.

CS_FORCE_CLOSE

The connection is closed whether or not results are pending, and without notifying the server.

This option is primarily for use when an application is hung waiting for a server response. It is also useful if ct_results, ct_fetch, or ct_cancel returns CS_FAIL.

Returns

ct_close returns the following values:

Return value

Meaning

CS_SUCCEED

The routine completed successfully.

CS_FAIL

The routine failed.

CS_PENDING

Asynchronous network I/O is in effect. See “Asynchronous programming”.

If asynchronous network I/O is in effect and ct_close is called with option as CS_FORCE_CLOSE, it returns CS_SUCCEED or CS_FAIL immediately to indicate the network response. In this case, no completion callback event occurs.

CS_BUSY

An asynchronous operation is already pending for this connection. See “Asynchronous programming”.

Note that ct_close does not return CS_BUSY when called with option as CS_FORCE_CLOSE.

The most common reason for a ct_close(CS_UNUSED) failure is pending results on the connection.

Examples

Example 1

CS_RETCODE retcode;
CS_INT close_option;
close_option = (status != CS_SUCCEED)? CS_FORCE_CLOSE :
               CS_UNUSED;

retcode = ct_close(connection, close_option);
if (retcode != CS_SUCCEED)
{
    ex_error("ex_con_cleanup: ct_close() failed");
    return retcode;
}

This code excerpt is from the exutils.c sample program.

Usage


Default close behavior


CS_FORCE_CLOSE behavior

See also

ct_callback, ct_con_drop, ct_connect, ct_con_props