Class Connections

Index Home MAE > MAE Architecture > MAE Data Types > Class Index > Class Connections

Summary
Public Methods
Connections()
inline int getFd() const
string getIpAddr() const
inline bool isLineOriented() const
inline bool isByteOriented() const
inline unsigned int getRemoteIpAddr() const
static inline int getNoConnections()
static inline Connections& getConnection(connNo)
static inline void setNoConnections(newNumber)
static inline void setGetConnectionFN(fn)
static inline void setAllocConnectionFN(fn)
static inline int setListeningForTcpConnections(listenFd)
static inline int setListeningForUnixConnections(listenFd)
inline void setLineOriented()
inline void setByteOriented()
inline void setRemoteIpAddr(newIpAddr)
inline bool ipc_eof()
static int getTcpService(service_name, defaultport)
static int startTcpListen(tcpServiceName, tcpserviceport, errmsg)
static int openUnixListen(socketName, errmsg)
void closeConnection()
string getConnHostname()
int transmit(text, size, debug_out)
inline int transmit(text)
inline int transmitDbg(text)
static Connections& findConnection(fd)
static void closeConnections()
static void sit_and_wait()
static Connections& addConnection(fd)
virtual unallocConnection()
virtual parseText(cmd)
inline unsigned long getInOctets() const
inline unsigned long getOutOctets() const
Protected Methods
int cache_size() const
void ipc_gets(cmd, maxSize)
Private Properties
Private Methods
static Connections& _getConnection(connNo)
static Connections& _allocConnection(newConnection)
int ipc_refresh_cache()
int ipc_append_cache()
void ipc_shift_cache()
int ipc_getc_cache()
bool cache_has_newline() const
bool cache_has_zero() const
bool ipc_writeready()
static void openTcpConnection(tcpserviceport)
void serviceConnection()
static void convertToAscii(buf, len, text)
static int convertFromBinary(text, buf)

#include <Connections.h >

Summary

This class contains all the OS-specific details needed to make various connections. Presumably there is one primary listening connection and possibly a series of additional connections to it. The primary connection is special. This class is used for both the primary connection and each additional connection.

The class accommodates two listening connections - a TCP fd and a Unix domain socket fd.

Each connection is given an connection number (or id) that is unique.  Note that fd's are recycled and therefore not unique across connections.

Public Methods

Connections()

Constructor.  Prepare to make connections.

inline int getFd() const

Return the OS file descriptor for the primary conneciton.

Return value: file descriptor, -1 if no connection

string getIpAddr() const

Return the IP address of the remote end of the connection

Return value: the IP address as N.N.N.N; 0.0.0.0 if none

inline bool isLineOriented() const

Determine if the primary connection is line oriented or not. If line

oriented, all traffic is transmitted in bursts separated by \n.

Return value: true if the connection is line oriented

inline bool isByteOriented() const

Determinen if the primary connection is byte-oriented or not.

Return value: true if connection is byte oriented

inline unsigned int getRemoteIpAddr() const

Get the primary remote connection's IPv4 address.

Return value: ip address as unsigned int

static inline int getNoConnections()

Get the current count on the number of additional connections.

Return value: the count of the number of additional connections; does not include the primary connection

static inline Connections& getConnection(connNo)

int connNo

the index into the table of additional connections


Get the connection information for an additional connection.

Return value: a Connections structure (check eof() if invalid)

static inline void setNoConnections(newNumber)

int newNumber

Set the connections cache size


Set the total number of connections. (Not sure why!)

static inline void setGetConnectionFN(fn)

GetConnectionFN fn

the new method to get a connection


Assign a new method to get a connection. This is handy when

a derived class wants to get its full class, not just this one.

static inline void setAllocConnectionFN(fn)

AllocConnectionFN fn

new conneciton allocation method


Setup a new connection allocation method.  This is handy when

a derived class wants to get its full class, not just this one.

static inline int setListeningForTcpConnections(listenFd)

int listenFd

a valid OS file descriptor from listen()


When the daemon listens on a particular fd for new TCP connections,

report that fd here so new connection requests can be handled.

Return value: the fd from input

static inline int setListeningForUnixConnections(listenFd)

int listenFd

a valid OS file descriptor from listen()


When the daemon listens on a particular fd for new Unix socket connections,

report that fd here so new connection requests can be handled.

Return value: the fd from input

inline void setLineOriented()

Specify this this connection is line oriented.

inline void setByteOriented()

Specify that this connection is byte oriented.

inline void setRemoteIpAddr(newIpAddr)

unsigned int newIpAddr

the IPv4 address


Set the remote connection's IPv4 address

inline bool ipc_eof()

Determine if the connection has terminated (reached EOF).

Return value: true if EOF reached

static int getTcpService(service_name, defaultport)

const string& service_name

the name of the TCP service (in /etc/services)

int defaultport

the port number to return if service name not found


Given a TCP service name, return its port number. If not found, return the default one provided.

Return value: the TCP service port

static int startTcpListen(tcpServiceName, tcpserviceport, errmsg)

const string& tcpServiceName

the name of the TCP service

int tcpserviceport

If less than 0, then use default port; If =0, then do not open a port; If >0, then open the specified port.

string& errmsg

(output) if failed, a description of why it failed


Open a TCP and listen to it for connections.

Return value: 1 on error (see errmsg), otherwise new listen() fd

static int openUnixListen(socketName, errmsg)

const string& socketName

filename in filesystem to use for socket

string& errmsg

(output) if failed, a description of why it failed


Open the Unix domain socket to listen for local connections.

Return value: 1 on error (see errmsg), otherwise new listen() fd

void closeConnection()

Close this conneciton.

string getConnHostname()

Get the hostname of the remote host connected on this connection.

Return value: remote hostname

int transmit(text, size, debug_out)

const char* text

the series of bytes to transmit

unsigned int size

the number of bytes to transmit

bool debug_out

true if debug output is desired

Default value: false


Send the provided text through the connection.

Return value: number of bytes transmitted

inline int transmit(text)

const string& text

text to send


Transmit a string of text through the connection

Return value: number of bytes transmitted

inline int transmitDbg(text)

const string& text

text to send


Transmit a string of text through the connection with debug output enabled.

Return value: number of bytes transmitted

static Connections& findConnection(fd)

int fd

the OS file descriptor


Given a fd, locate the connection.

Return value: a Connections instance; check getFd() to make sure its right

static void closeConnections()

Class all maintained connections

static void sit_and_wait()

Run a loop to wait for input on a connection and then service it.

static Connections& addConnection(fd)

int fd

the OS file descriptor


Add a new additional connection, using the Connection allocation method, if set, to return the app's instance.

Return value: the new connection

virtual unallocConnection()

Before a connection is destroyed, unallocate it.

virtual parseText(cmd)

const string& cmd

the input from the connection


Upon receiving input from a connection, process it.

inline unsigned long getInOctets() const

Return the total number of bytes/octets received

Return value: input byte count

inline unsigned long getOutOctets() const

Return the total number of bytes/octets transmitted

Return value: output byte count

Protected Methods

int cache_size() const

Return the number of bytes pending to be transmitted.

Return value: # of bytes pending

void ipc_gets(cmd, maxSize)

string& cmd

(output) the input line

int maxSize

if non-0, the maximum number of bytes to fetch

Default value: 0


Get a line of text from the input buffer of text received.

Private Properties

static int noConnections

Count of number of (active and inactive) connections

static vector <Connections > conn

Data for each connection

static GetConnectionFN getConnFN

If non-NULL, this is the app's function to find a connection; any superclass of this one should use this

static AllocConnectionFN allocConnFN

If non-NULL, this is the app's funciton to allocate a new connection; any superclass of this one should use this

int fd

socket fd for this connection

bool lineOriented

Flag: is this connection line oriented (so \n is separator)

unsigned int remoteIpAddr

Remote IP address of connection of this connection

bool eof

Flag: true if eof was found on this connection

unsigned char* cache

read cache for this conneciton

int cachesize

read cache circular queue indices for this conneciton

int cachepos

read cache circular queue indices for this conneciton

unsigned long inOctets

used for management - byte I/O count for this connection

unsigned long outOctets

used for management - byte I/O count for this connection

static int tcpListenFd

fd for listening for new TCP network connections

static int unixListenFd

fd for listening for new TCP network connections

unixListenFd; unixListenFd

fd for listenting for new socket connections

static unsigned long totalSessionCount

Management: session counters

static unsigned long totalUnixConnCount

Management: session counters

static unsigned long totalTcpConnCount

Management: session counters

static unsigned long totalInOctets

Management: total in/out bytes

static unsigned long totalOutOctets

Management: total in/out bytes


Private Methods

static Connections& _getConnection(connNo)

int connNo


Given a connection id/number, find the connection; used internally

static Connections& _allocConnection(newConnection)

Connections& newConnection


Allocate a new connection

int ipc_refresh_cache()

int ipc_append_cache()

void ipc_shift_cache()

int ipc_getc_cache()

bool cache_has_newline() const

bool cache_has_zero() const

bool ipc_writeready()

static void openTcpConnection(tcpserviceport)

int tcpserviceport


void serviceConnection()

static void convertToAscii(buf, len, text)

unsigned char* buf

int len

char* text


static int convertFromBinary(text, buf)

char* text

unsigned char* buf