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

TcpConnection Class Reference

Manages the yucky low-level TCP connections to other nodes. More...

#include <TcpConnection.h>

Inheritance diagram for TcpConnection::

BasicObject ConnectionInterface ObservableInterface List of all members.

Public Methods

 TcpConnection ()
 TcpConnection (SocketAddress)
 TcpConnection (IpAddress ipAddr, unsigned short port)
 TcpConnection (unsigned short port)
 for passive connections. More...

virtual ~TcpConnection ()
 Closes the connection if it is open. More...

virtual SocketAddressgetSocketAddress ()
virtual void setSocketAddress (SocketAddress *)
virtual int getStream ()
virtual void setStream (int stream)
 You can only set the stream if it isnt being used. More...

virtual int connect ()
 Connect to the IP address/port that is internally stored in this node. More...

virtual void close ()
 Close the stream to this node. More...

virtual int listen ()
 Used to accept incoming connections. More...

virtual ConnectionInterfaceaccept ()
 Accept handles incoming connect requests. More...

virtual bool isConnected ()
 Return true if we are connected to this Node, false otherwise. More...

virtual bool isConnectedTo (IpAddress)
 Return true if this nodes IP address matches the parameter, and we are currently connected to it. More...

virtual int read (unsigned char *buffer, int bufferSize, int amountToRead=0)
 Read data from the connection. More...

virtual int write (unsigned char *buffer, int amountToWrite)
 Write the data to the stream. More...

virtual ConnectionInterface::ObjectType getConnectionType ()
virtual void toStream (std::ostream &out)

Private Methods

void setSocketOptions ()
 Set our desired socket options for this application. More...


Static Private Methods

OS_SPEC_SOCKET_TYPE createListeningSocket (SocketAddress socketAddress)

Private Attributes

SocketAddress m_socketAddress
 The IP and port. More...

OS_SPEC_SOCKET_TYPE m_stream
 socket used to talk to a remote node; in the case of selfNode, all the listening sockets. More...

bool m_isActive
 true if connection type is active, false if passive. More...


Detailed Description

Manages the yucky low-level TCP connections to other nodes.

Definition at line 25 of file TcpConnection.h.


Constructor & Destructor Documentation

TcpConnection::TcpConnection
 

Definition at line 9 of file TcpConnection.cpp.

Referenced by accept().

TcpConnection::TcpConnection SocketAddress socketAddress
 

Definition at line 15 of file TcpConnection.cpp.

TcpConnection::TcpConnection IpAddress ipAddr,
unsigned short port
 

Definition at line 22 of file TcpConnection.cpp.

TcpConnection::TcpConnection unsigned short port
 

for passive connections.

Definition at line 32 of file TcpConnection.cpp.

TcpConnection::~TcpConnection [virtual]
 

Closes the connection if it is open.

Definition at line 42 of file TcpConnection.cpp.


Member Function Documentation

ConnectionInterface * TcpConnection::accept [virtual]
 

Accept handles incoming connect requests.

After a connection is accepted, is it treated exactly like all other connections.

Member function "listen" must be called before this function is called.

Returns:
the Node accepted from if successful, NULL otherwise

Reimplemented from ConnectionInterface.

Definition at line 266 of file TcpConnection.cpp.

Referenced by ProxyCommandProcessor::readCommand(), and HttpTestCommandProcessor::readCommand().

void TcpConnection::close [virtual]
 

Close the stream to this node.

Reimplemented from ConnectionInterface.

Definition at line 344 of file TcpConnection.cpp.

Referenced by HttpTestCommandProcessor::changePort(), WebServer::handleConnection(), ProxyCommandProcessor::readCommand(), HttpTestCommandProcessor::readCommand(), and ~TcpConnection().

int TcpConnection::connect [virtual]
 

Connect to the IP address/port that is internally stored in this node.

Returns:
1 if successful, 0 if unsuccessful

Reimplemented from ConnectionInterface.

Definition at line 79 of file TcpConnection.cpp.

Referenced by WebServer::handleConnection().

OS_SPEC_SOCKET_TYPE TcpConnection::createListeningSocket SocketAddress socketAddress [static, private]
 

Parameters:
socketAddress   The IP address and port to listen on, set IP to zero for loopback, set port to zero if you dont care which port to bind to.
Returns:
A pointer to a socket if successful, otherwise return OS_SPEC_INVALID_SOCKET

Definition at line 229 of file TcpConnection.cpp.

Referenced by listen().

ConnectionInterface::ObjectType TcpConnection::getConnectionType [virtual]
 

Reimplemented from ConnectionInterface.

Definition at line 48 of file TcpConnection.cpp.

SocketAddress * TcpConnection::getSocketAddress [virtual]
 

Reimplemented from ConnectionInterface.

Definition at line 388 of file TcpConnection.cpp.

Referenced by HttpTestCommandProcessor::HttpTestCommandProcessor(), HttpTestCommandProcessor::changePort(), ProxyCommandProcessor::toStream(), and HttpTestCommandProcessor::toStream().

int TcpConnection::getStream void [virtual]
 

Returns:
the socket descriptor

Reimplemented from ConnectionInterface.

Definition at line 403 of file TcpConnection.cpp.

Referenced by read(), ProxyCommandProcessor::readCommand(), and HttpTestCommandProcessor::readCommand().

bool TcpConnection::isConnected [virtual]
 

Return true if we are connected to this Node, false otherwise.

Reimplemented from ConnectionInterface.

Definition at line 362 of file TcpConnection.cpp.

Referenced by HttpTestCommandProcessor::HttpTestCommandProcessor(), close(), connect(), isConnectedTo(), read(), and setStream().

bool TcpConnection::isConnectedTo IpAddress ipAddr [virtual]
 

Return true if this nodes IP address matches the parameter, and we are currently connected to it.

Reimplemented from ConnectionInterface.

Definition at line 377 of file TcpConnection.cpp.

int TcpConnection::listen [virtual]
 

Used to accept incoming connections.

This sets up the socket to listen, but this does not start accepting connections. (It returns immediately)

Returns:
1 if successful, 0 if unsuccessful

Reimplemented from ConnectionInterface.

Definition at line 212 of file TcpConnection.cpp.

Referenced by HttpTestCommandProcessor::HttpTestCommandProcessor(), ProxyCommandProcessor::ProxyCommandProcessor(), and HttpTestCommandProcessor::changePort().

int TcpConnection::read unsigned char * buffer,
int bufferSize,
int amountToRead = 0
[virtual]
 

Read data from the connection.

Parameters:
buffer   Where to store the data read.
bufferSize   The size of the buffer in bytes.
amountToRead   The amount of data to read. The function will block until this much data has been read. If set to zero, the function will only block until it gets any amount of data.

Returns:
< 0 if there is an error, otherwise the number of bytes read

Reimplemented from ConnectionInterface.

Definition at line 132 of file TcpConnection.cpp.

Referenced by WebServer::handleConnection(), ProxyCommandProcessor::readCommand(), and HttpTestCommandProcessor::readCommand().

void TcpConnection::setSocketAddress SocketAddress * socketAddress [virtual]
 

Reimplemented from ConnectionInterface.

Definition at line 394 of file TcpConnection.cpp.

Referenced by HttpTestCommandProcessor::changePort().

void TcpConnection::setSocketOptions [private]
 

Set our desired socket options for this application.

Assumptions: socket has been created sucessfully.

Definition at line 58 of file TcpConnection.cpp.

Referenced by accept(), and connect().

void TcpConnection::setStream int stream [virtual]
 

You can only set the stream if it isnt being used.

Reimplemented from ConnectionInterface.

Definition at line 412 of file TcpConnection.cpp.

Referenced by accept().

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

Reimplemented from BasicObject.

Definition at line 420 of file TcpConnection.cpp.

int TcpConnection::write unsigned char * buffer,
int amountToWrite
[virtual]
 

Write the data to the stream.

Returns:
Number of bytes written, or the error code from system-level "send".

Reimplemented from ConnectionInterface.

Definition at line 182 of file TcpConnection.cpp.

Referenced by ProxyCommandProcessor::displayResponse(), HttpTestCommandProcessor::displayResponse(), and WebServer::handleConnection().


Member Data Documentation

bool TcpConnection::m_isActive [private]
 

true if connection type is active, false if passive.

Definition at line 62 of file TcpConnection.h.

SocketAddress TcpConnection::m_socketAddress [private]
 

The IP and port.

Definition at line 56 of file TcpConnection.h.

OS_SPEC_SOCKET_TYPE TcpConnection::m_stream [private]
 

socket used to talk to a remote node; in the case of selfNode, all the listening sockets.

Definition at line 59 of file TcpConnection.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