Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ServiceTable Class Reference

The ServiceTable keeps track of end-to-end connections. More...

#include <ServiceTable.h>

Inheritance diagram for ServiceTable::

BasicObject NetworkLayerListener PacketWriter List of all members.

Public Methods

 ServiceTable ()
 Create the ServiceTable. More...

virtual ~ServiceTable ()
 Destroy the ServiceTable. More...

int listenService ()
 Listens for connections from remote nodes and keeps the connection lists updated. More...

int connectService ()
 Tries to connect to a remote node. More...

int disconnectService (int serviceNumber)
 Disconnect a virtual circuit with the specified connection descriptor. More...

int sendData (int serviceNumber, u_char *buf, int bufLength)
 Causes "length" bytes of data stored at "msg" to be sent through the connection specified by the connection descriptor. More...

int receiveData (int serviceNumber, u_char *buf, int bufLength)
 Reassembles the data received on a service number. More...

void repairConnectionImpl (ServiceEntry *)
 This is a thread that gets called when a VC has been broken. More...

int generateConnectionDescriptor ()
 Generate a unique connection descriptor. More...

int generateServiceNumber ()
 Generate a unique service number. More...

void handleNetworkEvent (int eventCode, int vcn, NpPacket *packet)
 Called by network layer to inform the service table that something is up. More...

int sendDataPacket (int serviceNumber, TpPacket *queue)
 Sends data over the network by making a request to the networkLayer to send it. More...

NetworkLayergetNetworkLayer ()
 Return the network layer. More...

virtual void toStream (std::ostream &out)

Static Public Methods

void * repairConnection (void *arg)
 This is a thread that gets called when a VC has been broken. More...


Private Methods

ServiceEntrygetServiceEntry (int serviceNumber)
 Return the ServiceEntry associated with the serviceNum. More...

ServiceEntrygetServiceEntryByDescriptor (int connectionDescriptor)
 Return the ServiceEntry associated with the serviceNum. More...

void addServiceEntry (ServiceEntry *)
 Add the service entry object to the table. More...

bool removeServiceEntry (int serviceNumber)
 Remove the specified service entry from the table. More...

bool serviceExists (int serviceNumber)
 Returns true if the service exists. More...

bool handleDataPacket (int connectionDescriptor, NpPacket *packet)
 This function is called by the network layer. More...

int signalListenComplete (int connectionDescriptor)
 Called by network layer on a CONNECT message. More...

int signalConnectComplete (int connectionDescriptor)
 The network layer calls this function when it receives an EST message. More...

void signalDisconnect (int connectionDescriptor, NpPacket *packet)
 Called by network layer when it receives a FIN packet. More...

void signalBreak (int connectionDescriptor)
 This function is called by the network layer. More...


Private Attributes

list< ServiceEntry *> m_serviceList
 a linked list of ServiceEntry's. More...

Mutex m_serviceListLock
 lock for service list. More...

NetworkLayerm_networkLayer
 the network layer. More...

Counter m_serviceCount
 Used to assign new service numbers, service number of 0 is an error. More...

Counter m_descriptorCount
 Used to assign new connection descriptors, 0 is an error. More...

int m_receiveWindowSize
 the receive window size for ALL receive windows. More...

bool m_listening
 signifies whether the service table is listening for an EST message. More...

ThreadMessageQueue< ServiceEntrym_listenQueue
 an event queue. More...

bool m_listenThreadKilled
 Used when destroying the service table, this variable is used to signal to the listen thread to kill itself. More...


Friends

class ServiceTableCommand

Detailed Description

The ServiceTable keeps track of end-to-end connections.

A service number is the number given to a client of this system. A connection descriptor is a VCN. However, the connection descriptor can change during a transmission.

A service entry is kept around until disconnectService is called with its service number. If this is not called for every connection created or accepted, there will be a memory leak.

Todo:
make this work with multi-threading.

Definition at line 26 of file ServiceTable.h.


Constructor & Destructor Documentation

ServiceTable::ServiceTable
 

Create the ServiceTable.

This creates the NetworkLayer.

Definition at line 19 of file ServiceTable.cpp.

ServiceTable::~ServiceTable [virtual]
 

Destroy the ServiceTable.

Todo:
This function is not 100% guarenteed to work. It would be nice to verify that the listen thread is done before exiting this function.

Definition at line 40 of file ServiceTable.cpp.


Member Function Documentation

void ServiceTable::addServiceEntry ServiceEntry * serviceEntry [private]
 

Add the service entry object to the table.

Definition at line 111 of file ServiceTable.cpp.

Referenced by connectService(), and listenService().

int ServiceTable::connectService
 

Tries to connect to a remote node.

It will try a up to CONNECTION_MAX_TRIES times before giving up.

Returns:
the service number assigned to this connection.

Definition at line 145 of file ServiceTable.cpp.

Referenced by TransportLayer::connect().

int ServiceTable::disconnectService int serviceNumber
 

Disconnect a virtual circuit with the specified connection descriptor.

Definition at line 242 of file ServiceTable.cpp.

Referenced by TransportLayer::disconnect(), and signalDisconnect().

int ServiceTable::generateConnectionDescriptor [virtual]
 

Generate a unique connection descriptor.

Reimplemented from NetworkLayerListener.

Definition at line 474 of file ServiceTable.cpp.

Referenced by ServiceEntry::toConnectingState(), and ServiceEntry::toReconnectingState().

int ServiceTable::generateServiceNumber
 

Generate a unique service number.

Definition at line 329 of file ServiceTable.cpp.

Referenced by ServiceEntry::connectionAccepted(), and ServiceEntry::toConnectingState().

NetworkLayer * ServiceTable::getNetworkLayer
 

Return the network layer.

Definition at line 66 of file ServiceTable.cpp.

Referenced by TransportLayer::getNetworkLayer().

ServiceEntry * ServiceTable::getServiceEntry int serviceNum [private]
 

Return the ServiceEntry associated with the serviceNum.

Definition at line 75 of file ServiceTable.cpp.

Referenced by disconnectService(), receiveData(), sendData(), sendDataPacket(), and serviceExists().

ServiceEntry * ServiceTable::getServiceEntryByDescriptor int connectionDescriptor [private]
 

Return the ServiceEntry associated with the serviceNum.

Definition at line 93 of file ServiceTable.cpp.

Referenced by handleDataPacket(), signalBreak(), signalConnectComplete(), signalDisconnect(), and signalListenComplete().

bool ServiceTable::handleDataPacket int connectionDescriptor,
NpPacket * packet
[private]
 

This function is called by the network layer.

Gives the data packet to the SAR object for the specified connection.

Returns:
true if we were able to add the data to the SAR, false if the connectionEntry could not be found.

Definition at line 625 of file ServiceTable.cpp.

Referenced by handleNetworkEvent().

void ServiceTable::handleNetworkEvent int eventCode,
int vcn,
NpPacket * packet
[virtual]
 

Called by network layer to inform the service table that something is up.

Reimplemented from NetworkLayerListener.

Definition at line 484 of file ServiceTable.cpp.

int ServiceTable::listenService
 

Listens for connections from remote nodes and keeps the connection lists updated.

only upon receipt of a server connection does this function return. It adds new connections to the connection lists, and removes connections that have died. It also kills a service if requested and there are no more connections running on that service.

Definition at line 196 of file ServiceTable.cpp.

Referenced by TransportLayer::listenAccept().

int ServiceTable::receiveData int serviceNumber,
u_char * buf,
int bufLength
 

Reassembles the data received on a service number.

Note: BAD things happen if service entry deleted while this is happening.

Returns:
the length of the message.

Todo:
This isnt returning when the connection has been closed.

Definition at line 309 of file ServiceTable.cpp.

Referenced by TransportLayer::receive().

bool ServiceTable::removeServiceEntry int serviceNumber [private]
 

Remove the specified service entry from the table.

Definition at line 121 of file ServiceTable.cpp.

Referenced by connectService(), disconnectService(), and repairConnectionImpl().

void * ServiceTable::repairConnection void * arg [static]
 

This is a thread that gets called when a VC has been broken.

We repair the connection and then restart transmission.

Parameters:
arg   The ConnectionEntry that has broken.

Definition at line 362 of file ServiceTable.cpp.

void ServiceTable::repairConnectionImpl ServiceEntry * serviceEntry
 

This is a thread that gets called when a VC has been broken.

We repair the connection and then restart transmission.

Parameters:
arg   The ConnectionEntry that has broken.

Definition at line 387 of file ServiceTable.cpp.

Referenced by repairConnection().

int ServiceTable::sendData int serviceNumber,
u_char * buf,
int bufLength
 

Causes "length" bytes of data stored at "msg" to be sent through the connection specified by the connection descriptor.

This function blocks till return. Upon return, application should be able to write-over the data at "msg" without affecting the actual data sent.

Note: Its BAD if entry gets deleted midway through a send.

Parameters:
serviceNumber   Identifier for the connection.
buf   The data to be sent.
bufLength   The length of buf, in bytes.

Returns:
The number of data bytes sent, or PB_ERROR. PB_ERROR - either msg not a valid pointer, length not a positive integer, or connection_descriptor not valid (negative), or connection severed during transmission and was unable to reconnect.

Definition at line 280 of file ServiceTable.cpp.

Referenced by TransportLayer::send().

int ServiceTable::sendDataPacket int serviceNumber,
TpPacket * packet
[virtual]
 

Sends data over the network by making a request to the networkLayer to send it.

Return the number of bytes sent if packet sent successfully, or PB_BAD_SERVICE if the service doesnt exist.

Reimplemented from PacketWriter.

Definition at line 650 of file ServiceTable.cpp.

bool ServiceTable::serviceExists int serviceNumber [private]
 

Returns true if the service exists.

Definition at line 338 of file ServiceTable.cpp.

void ServiceTable::signalBreak int connectionDescriptor [private]
 

This function is called by the network layer.

Spawns a repair thread to fix the broken connection.

Definition at line 536 of file ServiceTable.cpp.

Referenced by handleNetworkEvent(), and signalDisconnect().

int ServiceTable::signalConnectComplete int connectionDescriptor [private]
 

The network layer calls this function when it receives an EST message.

Returns:
The connection descriptor passed in, or ST_NOT_EXPECTING_CONNECTION on error.

Definition at line 591 of file ServiceTable.cpp.

Referenced by handleNetworkEvent().

void ServiceTable::signalDisconnect int connectionDescriptor,
NpPacket * npPacket
[private]
 

Called by network layer when it receives a FIN packet.

Definition at line 509 of file ServiceTable.cpp.

Referenced by handleNetworkEvent().

int ServiceTable::signalListenComplete int connectionDescriptor [private]
 

Called by network layer on a CONNECT message.

Returns:
the connectionDescriptor passed in, or ST_NOT_EXPECTING_CONNECTION on error.

Definition at line 566 of file ServiceTable.cpp.

Referenced by handleNetworkEvent().

void ServiceTable::toStream std::ostream & out [virtual]
 

Reimplemented from BasicObject.

Definition at line 661 of file ServiceTable.cpp.


Friends And Related Function Documentation

friend class ServiceTableCommand [friend]
 

Definition at line 57 of file ServiceTable.h.


Member Data Documentation

Counter ServiceTable::m_descriptorCount [private]
 

Used to assign new connection descriptors, 0 is an error.

Definition at line 100 of file ServiceTable.h.

ThreadMessageQueue<ServiceEntry> ServiceTable::m_listenQueue [private]
 

an event queue.

Definition at line 109 of file ServiceTable.h.

bool ServiceTable::m_listenThreadKilled [private]
 

Used when destroying the service table, this variable is used to signal to the listen thread to kill itself.

Definition at line 113 of file ServiceTable.h.

bool ServiceTable::m_listening [private]
 

signifies whether the service table is listening for an EST message.

Definition at line 106 of file ServiceTable.h.

NetworkLayer* ServiceTable::m_networkLayer [private]
 

the network layer.

Definition at line 94 of file ServiceTable.h.

int ServiceTable::m_receiveWindowSize [private]
 

the receive window size for ALL receive windows.

Definition at line 103 of file ServiceTable.h.

Counter ServiceTable::m_serviceCount [private]
 

Used to assign new service numbers, service number of 0 is an error.

Definition at line 97 of file ServiceTable.h.

list<ServiceEntry*> ServiceTable::m_serviceList [private]
 

a linked list of ServiceEntry's.

Definition at line 88 of file ServiceTable.h.

Mutex ServiceTable::m_serviceListLock [private]
 

lock for service list.

Definition at line 91 of file ServiceTable.h.


The documentation for this class was generated from the following files:
Generated at Thu Jul 11 13:31:59 2002 for Peekabooty by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001