libcom_tcp.c File Reference

TCP instantiation of lowlevel communication primitives for OAA. More...

#include <sys/param.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <math.h>
#include "libcom_tcp.h"
#include "libdb.h"
#include "libutils.h"
#include "libicl_private.h"
#include "libicl.h"
#include "libicl_depr.h"
#include "termreader.h"
#include "stringtermreader.h"
#include "binarytermreader.h"
#include "termsender.h"
#include "stringtermsender.h"
#include "binarytermsender.h"
#include "liboaa.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <strings.h>
#include <unistd.h>
#include <sys/time.h>

Go to the source code of this file.

Defines

#define EXPORT_BORLAND
#define EXPORT_MSCPP
#define OAA_BINARY_PORT_OFFSET   10
#define STREQ(str1, str2)   (strcmp((str1), (str2)) == 0)

Functions

int com_ask_about_tcp_exception (int Port, char *Host)
void tcpShutdown (SOCKET socket)
 Shuts down an open socket.
SOCKET tcpConnect (char *hostName, int port)
 Given a host and port, connect to the server socket.
int tcpSelect (SOCKET socket, double timeout)
 Wait for socket input, or until timeout.
EXTERN void comPrintError (char *str,...)
 Prints out tcpError messages.
EXPORT_MSCPP SOCKET EXPORT_BORLAND com_Connect (char *ConnectionId, ICLTerm *Address)
 Given a connection ID and an address, initiates a client connection.
EXPORT_MSCPP SOCKET EXPORT_BORLAND comConnectFormat (char *ConnectionId, ICLTerm *Params, ICLTerm *Address, int format)
EXPORT_MSCPP int EXPORT_BORLAND com_Disconnect (char *ConnectionId)
 Given a connection ID, shuts down the connection.
EXPORT_MSCPP SOCKET EXPORT_BORLAND com_Connected (char *ConnectionId)
 Return TRUE if the TCP connection is established.
EXPORT_MSCPP int EXPORT_BORLAND com_GetAllValidConnections (ICLTerm **result)
int com_GetConnectionFromInfo (ICLTerm *Info, char **connectionName)
 Looks up a connection that contains a given information.
EXPORT_MSCPP int EXPORT_BORLAND com_ListenAt (char *ConnectionId, ICLTerm *Params, ICLTerm *Address)
 Given a connection ID and an address, initiate a server connection.
void com_print_tcp_exception_help ()
int com_get_socket_from_connection_id (char *ConnectionId)
 Looks up the local connections database to extract a socket id.
int basic_send (SOCKET inSocket, char *Data, int Size)
 Sends data to the specified connection ID.
EXPORT_MSCPP int EXPORT_BORLAND com_SendData (char *ConnectionId, char *Data, int Size)
 Sends data to the specified connection ID.
EXPORT_MSCPP int EXPORT_BORLAND com_SendTerm (char *connectionId, ICLTerm *term)
EXPORT_MSCPP int EXPORT_BORLAND com_AddInfo (char *ConnectionId, ICLTerm *NewInfo)
 Records data about the specified connection ID.
EXPORT_MSCPP int EXPORT_BORLAND com_RemoveInfo (char *connectionId, ICLTerm *toMatch)
 Remove info about the specified connection ID.
EXPORT_MSCPP int EXPORT_BORLAND com_UpdateInfo (char *ConnectionId, ICLTerm *NewInfo)
 Updates data about the specified connection ID.
EXPORT_MSCPP int EXPORT_BORLAND com_GetInfo (char *ConnectionId, ICLTerm *GInfo, ICLTerm **Result)
 Looks up info based on the connection id.
EXPORT_MSCPP int EXPORT_BORLAND com_GetConnectionId (char **ConnectionId, ICLTerm *GInfo)
 Looks up connection id based on oaa_name, oaa_id, or fac_id,.
EXPORT_MSCPP int EXPORT_BORLAND com_SelectEvent (char *inConnectionId, double timeout, ICLTerm **event)
EXPORT_MSCPP char *EXPORT_BORLAND com_GetDefaultConnectionId ()
 Looks up the current ConnectionId.
EXPORT_MSCPP void EXPORT_BORLAND cnx_CanonicalAddress (ICLTerm *address, SOCKET socket, ICLTerm **result)
 Returns address tcp(IPAddr,Port) to connected socket.
EXPORT_MSCPP int EXPORT_BORLAND com_GetEventFromConnection (char *ConnectionId, double timeout, ICLTerm **event)
 Get an event from a specific connection.
EXPORT_MSCPP int EXPORT_BORLAND com_SelectEventFromAllIds (double timeout, ICLTerm **event)
 Similar to the original com_SelectEvent(), this function selects from all the connections.

Variables

const char * oaa_library_version_str
int COM_BEST_FORMAT = 100
int COM_STRING_FORMAT = 1
int COM_BINARY_FORMAT = 2
ICLDatabasecommdb = NULL
char const * commonStart = "event(ev_connect(["
char const * commonEnd = "query_formats(_),other_name('libcom_tcp_formatRequest_shouldDisconnect'),other_type(client)]),[])"
char const * otherVersionStart = "other_version("
char const * otherVersionEnd = ")"
char const * passwordStart = "password("
char const * passwordEnd = ")"
char const * comma = ","
int initializedLastFired = FALSE


Detailed Description

TCP instantiation of lowlevel communication primitives for OAA.

Definition in file libcom_tcp.c.


Define Documentation

#define EXPORT_BORLAND

Definition at line 29 of file libcom_tcp.c.

#define EXPORT_MSCPP

Definition at line 34 of file libcom_tcp.c.

#define OAA_BINARY_PORT_OFFSET   10

Definition at line 37 of file libcom_tcp.c.

#define STREQ ( str1,
str2   )     (strcmp((str1), (str2)) == 0)

Definition at line 71 of file libcom_tcp.c.


Function Documentation

int basic_send ( SOCKET  inSocket,
char *  Data,
int  Size 
)

Sends data to the specified connection ID.

For compatibility between Windows and UNIX.

Definition at line 964 of file libcom_tcp.c.

EXPORT_MSCPP void EXPORT_BORLAND cnx_CanonicalAddress ( ICLTerm address,
SOCKET  socket,
ICLTerm **  result 
)

Returns address tcp(IPAddr,Port) to connected socket.

Must be connected first, for this to work! Currently, assumes client connection (should change!)

Definition at line 1664 of file libcom_tcp.c.

EXPORT_MSCPP int EXPORT_BORLAND com_AddInfo ( char *  ConnectionId,
ICLTerm NewInfo 
)

Records data about the specified connection ID.

Info may be status(S), type(T), protocol(P) or any element (or list of elements) to be stored in InfoList.

Returns:
TRUE if success

Definition at line 1048 of file libcom_tcp.c.

int com_ask_about_tcp_exception ( int  Port,
char *  Host 
)

Definition at line 913 of file libcom_tcp.c.

EXPORT_MSCPP SOCKET EXPORT_BORLAND com_Connect ( char *  ConnectionId,
ICLTerm Address 
)

Given a connection ID and an address, initiates a client connection.

Remarks:

Definition at line 219 of file libcom_tcp.c.

EXPORT_MSCPP SOCKET EXPORT_BORLAND com_Connected ( char *  ConnectionId  ) 

Return TRUE if the TCP connection is established.

Definition at line 675 of file libcom_tcp.c.

EXPORT_MSCPP int EXPORT_BORLAND com_Disconnect ( char *  ConnectionId  ) 

Given a connection ID, shuts down the connection.

If Id is NULL, shuts down all connections.

Note: Succeeds silently if there is not an open connection having the given id.

Definition at line 639 of file libcom_tcp.c.

int com_get_socket_from_connection_id ( char *  ConnectionId  ) 

Looks up the local connections database to extract a socket id.

Returns:
the socket id as int, or -1 if fails

Definition at line 939 of file libcom_tcp.c.

EXPORT_MSCPP int EXPORT_BORLAND com_GetAllValidConnections ( ICLTerm **  result  ) 

Definition at line 701 of file libcom_tcp.c.

int com_GetConnectionFromInfo ( ICLTerm Info,
char **  connectionName 
)

Looks up a connection that contains a given information.

Returns:
NULL if fail, an IclTerm if success.

Definition at line 742 of file libcom_tcp.c.

EXPORT_MSCPP int EXPORT_BORLAND com_GetConnectionId ( char **  ConnectionId,
ICLTerm GInfo 
)

Looks up connection id based on oaa_name, oaa_id, or fac_id,.

Returns:
TRUE if success

Definition at line 1381 of file libcom_tcp.c.

EXPORT_MSCPP char* EXPORT_BORLAND com_GetDefaultConnectionId (  ) 

Looks up the current ConnectionId.

Assumes there is only one connection ID and returns the first. Returns the connection in a new space which should be free'd.

Returns:
the connectionId or NULL if none available

Definition at line 1634 of file libcom_tcp.c.

EXPORT_MSCPP int EXPORT_BORLAND com_GetEventFromConnection ( char *  ConnectionId,
double  timeout,
ICLTerm **  event 
)

Get an event from a specific connection.

Definition at line 1969 of file libcom_tcp.c.

EXPORT_MSCPP int EXPORT_BORLAND com_GetInfo ( char *  ConnectionId,
ICLTerm GInfo,
ICLTerm **  Result 
)

Looks up info based on the connection id.

Returns:
TRUE if success

Definition at line 1306 of file libcom_tcp.c.

EXPORT_MSCPP int EXPORT_BORLAND com_ListenAt ( char *  ConnectionId,
ICLTerm Params,
ICLTerm Address 
)

Given a connection ID and an address, initiate a server connection.

Remarks:

Definition at line 781 of file libcom_tcp.c.

void com_print_tcp_exception_help (  ) 

Definition at line 891 of file libcom_tcp.c.

EXPORT_MSCPP int EXPORT_BORLAND com_RemoveInfo ( char *  connectionId,
ICLTerm toMatch 
)

Remove info about the specified connection ID.

Info may only be an an element stored in the InfoList

Definition at line 1130 of file libcom_tcp.c.

EXPORT_MSCPP int EXPORT_BORLAND com_SelectEvent ( char *  inConnectionId,
double  timeout,
ICLTerm **  event 
)

Definition at line 1428 of file libcom_tcp.c.

EXPORT_MSCPP int EXPORT_BORLAND com_SelectEventFromAllIds ( double  timeout,
ICLTerm **  event 
)

Similar to the original com_SelectEvent(), this function selects from all the connections.

It also checks the listen sockets, if any, for incoming connection requests.

The main select() statement is contained in com_read_events_into_buffer().

Definition at line 2414 of file libcom_tcp.c.

EXPORT_MSCPP int EXPORT_BORLAND com_SendData ( char *  ConnectionId,
char *  Data,
int  Size 
)

Sends data to the specified connection ID.

Returns:
TRUE if success

Definition at line 986 of file libcom_tcp.c.

EXPORT_MSCPP int EXPORT_BORLAND com_SendTerm ( char *  connectionId,
ICLTerm term 
)

Definition at line 1012 of file libcom_tcp.c.

EXPORT_MSCPP int EXPORT_BORLAND com_UpdateInfo ( char *  ConnectionId,
ICLTerm NewInfo 
)

Updates data about the specified connection ID.

Info may be status(S), type(T), protocol(P) or any element (or list of elements) to be stored in InfoList.

Returns:
TRUE if success

Definition at line 1195 of file libcom_tcp.c.

EXPORT_MSCPP SOCKET EXPORT_BORLAND comConnectFormat ( char *  ConnectionId,
ICLTerm Params,
ICLTerm Address,
int  format 
)

Definition at line 358 of file libcom_tcp.c.

EXTERN void comPrintError ( char *  str,
  ... 
)

Prints out tcpError messages.

Definition at line 1461 of file libcom_tcp.c.

SOCKET tcpConnect ( char *  hostName,
int  port 
)

Given a host and port, connect to the server socket.

Parameters:
hostName may be a host ID or IP address
port port to connect to on hostName
Returns:
file descriptor to socket or -1 if failure

Definition at line 1543 of file libcom_tcp.c.

int tcpSelect ( SOCKET  socket,
double  timeout 
)

Wait for socket input, or until timeout.

Parameters:
socket the socket to wait for
timeout the max wait time in seconds (if 0, blocks)
Returns:
the number of file descriptors read

Definition at line 1593 of file libcom_tcp.c.

void tcpShutdown ( SOCKET  socket  ) 

Shuts down an open socket.

Parameters:
socket the socket to close

Definition at line 1511 of file libcom_tcp.c.


Variable Documentation

int COM_BEST_FORMAT = 100

Definition at line 74 of file libcom_tcp.c.

int COM_BINARY_FORMAT = 2

Definition at line 76 of file libcom_tcp.c.

int COM_STRING_FORMAT = 1

Definition at line 75 of file libcom_tcp.c.

char const* comma = ","

Definition at line 230 of file libcom_tcp.c.

ICLDatabase* commdb = NULL

Definition at line 90 of file libcom_tcp.c.

char const* commonEnd = "query_formats(_),other_name('libcom_tcp_formatRequest_shouldDisconnect'),other_type(client)]),[])"

Definition at line 225 of file libcom_tcp.c.

char const* commonStart = "event(ev_connect(["

Definition at line 224 of file libcom_tcp.c.

int initializedLastFired = FALSE

Definition at line 2372 of file libcom_tcp.c.

const char* oaa_library_version_str

Deprecated:
use oaa_LibraryVersion()

Definition at line 145 of file liboaa.h.

char const* otherVersionEnd = ")"

Definition at line 227 of file libcom_tcp.c.

char const* otherVersionStart = "other_version("

Definition at line 226 of file libcom_tcp.c.

char const* passwordEnd = ")"

Definition at line 229 of file libcom_tcp.c.

char const* passwordStart = "password("

Definition at line 228 of file libcom_tcp.c.


Generated on Wed May 23 17:20:14 2007 using doxygen 1.5.2