Allocate a CS_CONNECTION structure.
CS_RETCODE ct_con_alloc(context, con_pointer) CS_CONTEXT *context; CS_CONNECTION **con_pointer;
A pointer to a CS_CONTEXT structure.
The address of a pointer variable. ct_con_alloc sets *con_pointer to the address of a newly allocated CS_CONNECTION structure.
ct_con_alloc returns the following values:
Return value |
Meaning |
---|---|
CS_SUCCEED |
The routine completed successfully |
CS_FAIL |
The routine failed |
The most common reason for a ct_con_alloc failure is a lack of adequate memory.
/*
** DoConnect()
**
** Type of function:
** async example program api
*/
CS_STATIC CS_CONNECTION CS_INTERNAL *
DoConnect(argc, argv)
int argc;
char **argv;
{
CS_CONNECTION *connection;
CS_INT netio_type = CS_ASYNC_IO;
CS_RETCODE retcode;
/* Open a connection to the server */
retcode = ct_con_alloc(Ex_context, &connection);
if (retcode != CS_SUCCEED)
{
ex_panic("ct_con_alloc failed");
}
/* Set properties for the connection */
...ct_con_props calls deleted ...
/* Open the connection */
...ct_connect call deleted.....
}
A CS_CONNECTION structure, also called a connection structure, contains information about a particular client/server connection.
Before calling ct_con_alloc, an application must allocate a context structure by calling the CS-Library routine cs_ctx_alloc, and must initialize Client-Library by calling ct_init.
Connecting to a server is a three-step process. To connect to a server, an application:
Calls ct_con_alloc to allocate a CS_CONNECTION structure.
Calls ct_con_props to set the values of connection-specific properties, if desired.
Calls ct_connect to create the connection and log in to the server.
An application can have multiple open connections to one or more servers at the same time.
For example, an application can simultaneously have two connections to the server MARS, one connection to VENUS, and one connection to PLUTO. The context property CS_MAX_CONNECT, set by ct_config, determines the maximum number of open connections allowed per context.
Each server connection requires a separate CS_CONNECTION structure.
To send commands to a server, one or more command structures must be allocated for a connection. ct_cmd_alloc allocates a command structure.
cs_ctx_alloc, ct_cmd_alloc, ct_close, ct_connect, ct_con_props