Understanding SQL*Net | Library |
Product |
Contents |
Index |
By exposing an interface to SQL*Net, SQL*Net OPEN provides applications a single common interface to all industry standard network protocols. With SQL*Net, database applications can connect to other database applications across networks with different protocols. SQL*Net OPEN extends this connectivity to non-database applications.
SQL*Net OPEN provides a simple and portable call interface that enables developers to build truly portable network applications. They can rapidly deploy an application developed on one machine to another without having to modify their calls to the network interface.
The relationship of SQL*Net OPEN to other products is shown in Figure D - 1.
Figure D - 1. SQL*Net OPEN
No additional programming is required to take advantage of the MultiProtocol Interchange. Its transfer of data across protocols is transparent to both users and programmers.
The API as currently provided supports the C language. Examples given in this documentation are in C. Names used in API begin with "TNS," which stands for Transparent Network Substrate, the network transport technology on which SQL*Net version2 is based. For more information about TNS, refer to Chapter 2 in this manual.
#include <tnsapi.h>
Your makefile (or other location for your build command) should ensure that the include path is set properly so that tnsapi.h will be found. Refer to the sample makefiles provided in your installation.
The SQL*Net OPEN API functions are described in the next sections:
int tnsopen(handlep, name) void **handlep; const char *name;
Description Initializes the SQL*Net OPEN API per-connection handle. This function must be the first SQL*Net OPEN call that a user makes. Note that tnsopen() does not establish a connection; connections are established by the send and receive calls as needed. See the sections on tnssend() and tnsrecv() below.
If you're writing a client program (which will initiate the connection), "name" contains a service name in the same format as those in the SQL*Net configuration file TNSNAMES.ORA.
If you're writing a server program, "name" should be NULL. The connection will automatically be picked up by your server program when you make the first tnsrecv() call to receive data (see the section on tnsrecv, below.)
Parameters
handlep (IN/OUT) - Address to receive SQL*Net connection handle
name (IN) - service name
Prerequisites The handlep parameter must not be NULL
Returns Upon successful completion a zero value is returned. Otherwise, a positive SQL*Net API error is returned, as listed in the SQL*Net OPEN API Errors section.
int tnsclose(handlep) void **handlep;
Description Shuts down the connection. This function must be called by the user to close the connection and release the handle properly.
Parameters
handlep(IN/OUT) - Address of a pointer to a SQL*Net connection handle
Prerequisites The handlep parameter must not be NULL.
Returns Upon successful completion a zero value is returned, and *handlep is set to NULL. Otherwise, a positive SQL*Net API error number is returned.
int tnssend(handle, data, length) void *handle; const void *data; size_t *length;
Description Send data to the SQL*Net connection handle.
In the first call to tnssend() on the client side, the connection is established before any data is sent to the handle. The client application must first call tnssend() after tnsopen() to establish a connection to the server. It is an error if the client application calls tnsrecv() first, or if the server program calls tnssend() first.
Note that this also means that the tnssend() call may return errors related to connection establishment - so the first indication you get that, for instance, you've given the incorrect TNS address, is that an error occurs on the first tnssend() call, rhater than on the tnsopen() call as you may first expect.
Parameters
handle(IN/OUT) - pointer to SQL*Net connection handle returned by tnsopen() data(IN) - pointer to data to be sent length(IN/OUT) - pointer to the length of data to be sent in bytes and the actual number of bytes written on return.
Prerequisites The parameters must not be NULL.
Returns Upon successful completion a zero value is returned, and the actual number of bytes written is returned as the value pointed to by the length parameter. Otherwise, a positive SQL*Net API error number is returned.
int tnsrecv(handle, data, length) void *handle; void *data; size_t *length;
Description Receive data from the SQL*Net connection handle.
In the first call to tnsrecv() on the server side, the connection is established before data is received from the handle. The server must first call tnsrecv() after tnsopen() to accept the connection from the client.
Incoming connections are accepted by the SQL*Net Listener (tnslsnr), which automatically spawns off a copy of your server program when needed, and hands it the new connection. You must configure the network listener with the location of your server program for this to occur -- see the section on configuration below.
Parameters
handle(IN/OUT) - pointer to SQL*Net connection handle returned by tnsopen() data(IN/OUT) - pointer to buffer to receive data length(IN/OUT) - pointer to the length of buffer to receive data and actual number of bytes received on return
Prerequisites All parameters must not be NULL.
Returns Upon successful completion a zero value is returned, and the actual number of bytes received is returned as the value pointed to by the length parameter. Otherwise, a positive SQL*Net API error number is returned.
int tnscontrol (handle, cmd) void *handle; int cmd;
Description Set an option on a connection handle
Parameters
handle (IN) pointer to TNS connection handle as returned by tnsopen() cmd (IN) option to apply to the connection. Currently supported values are: TNSAPINONBLOCKING - set connection into nonblocking mode TNSAPIBLOCKING - set connection into blocking mode
Requires handle must not be NULL, and cmd must be one of the supported commands.
Returns A zero value is returned if option is successfully set.
20002 - SDFAIL_TNSAPIE - The underlying "send" command failed in tnssend().
20003 - RECVFAIL_TNSAPIE - The underlying "receive" command failed in tnsrecv().
20004 - INVSVROP_TNSAPIE - Operation is invalid as the server.
20005 - INVCLIOP_TNSAPIE - Operation is invalid as the client.
20006 - HDLUNINI_TNSAPIE - The connection should be initialized by calling tnsopen().
20007 - INHFAIL_TNSAPIE - Server failed in inheriting the connection from the listener.
20008 - ACPTFAIL_TNSAPIE - Server failed in accepting the connection request from the client.
20009 - NULHDL_TNSAPIE - A null handle was passed into the call, which is not allowed.
20010 - INVOP_TNSAPIE - An invalid operation called was passed into the call.
20011 - MALFAIL_TNSAPIE - A malloc failed in TNS API call.
20012 - NLINIFAIL_TNSAPIE - Failed in NL initialization.
20013 - NMTOOLONG_TNSAPIE - Service name is too long.
20014 - CONFAIL_TNSAPIE - Client connect request failed.
20015 - LSNFAIL_TNSAPIE - Server failed to listen for connect request.
20016 - ANSFAIL_TNSAPIE - Server failed to answer connect request.
20017 - NMRESFAIL_TNSAPIE - Failed to resolve service name.
20018 - WOULDBLOCK_TNSAPIE - operation would block.
20019 - CTLFAIL_TNSAPIE - control call failed.
20020 - TNSAPIE_ERROR - TNS error occurred.
20021 - INVCTL_TNSAPIE - invalid operation requested in control call.
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = chatsid) /*your SID name*/ (ORACLE_HOME = /usr/oracle) /*your ORACLE_HOME name*/ (PROGRAM = chatsvr) /*the name of your server program*/ )
Note: There may be additional SIDs in the list as well, configured with Network Manager.
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=unixhost)(PORT=1521)))
chat=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=unixhost) (PORT=1521))(CONNECT_DATA=(SID=chatsid)))
Prev Next |
Copyright © 1996 Oracle Corporation. All Rights Reserved. |
Library |
Product |
Contents |
Index |