eq::net::Connection Class Reference

#include <connection.h>

Inheritance diagram for eq::net::Connection:

Inheritance graph
[legend]
Collaboration diagram for eq::net::Connection:

Collaboration graph
[legend]

List of all members.


Detailed Description

A base class to provide communication to other hosts.

Definition at line 42 of file connection.h.


Messaging API

enum  SelectResult { SELECT_TIMEOUT = 0, SELECT_ERROR = -1 }
typedef int ReadNotifier
State _state
 The connection state.
ConnectionDescriptionPtr _description
base::SpinLock _sendLock
std::vector< ConnectionListener * > _listeners
 The listeners on state changes.
class PairConnection
static bool send (const ConnectionVector &connections, const Packet &packet, const bool isLocked=false)
 Sends a packaged message to multiple connections.
static bool send (const ConnectionVector &connections, Packet &packet, const void *data, const uint64_t size, const bool isLocked=false)
 Sends a packaged message including additional data to multiple connections.
bool recv (void *buffer, const uint64_t bytes)
 Read data from the connection.
void lockSend () const
 Lock the connection, no other thread can send data.
void unlockSend () const
 Unlock the connection.
bool send (const void *buffer, const uint64_t bytes, const bool isLocked=false) const
 Sends data using the connection.
bool send (const Packet &packet) const
 Sends a packaged message using the connection.
bool send (Packet &packet, const std::string &string) const
 Sends a packaged message including a string using the connection.
template<typename T>
bool send (Packet &packet, const std::vector< T > &data) const
 Sends a packaged message including additional data.
bool send (Packet &packet, const void *data, const uint64_t size) const
 Sends a packaged message including additional data using the connection.
virtual ReadNotifier getReadNotifier () const
 Connection ()
 Connection (const Connection &conn)
virtual ~Connection ()
void _fireStateChanged ()

Public Types

enum  State { STATE_CLOSED, STATE_CONNECTING, STATE_CONNECTED, STATE_LISTENING }

Public Member Functions

template<typename T>
bool send (Packet &packet, const std::vector< T > &data) const
Data Access.
State getState () const
 Returns the state of this connection.
bool isClosed () const
bool isConnected () const
bool isListening () const
void setDescription (ConnectionDescriptionPtr description)
 Set the connection's description.
ConnectionDescriptionPtr getDescription () const
Connection Management
virtual bool connect ()
 Connect to the remote peer.
virtual bool listen ()
 Put the connection into the listening state for a new incoming connection.
virtual ConnectionPtr accept ()
 Accepts the next incoming connection.
virtual ConnectionPtr accept (const int timeout)
 Accepts the next incoming connection with a timeout.
virtual void close ()
 Closes a connected or listening connection.
Listener Interface
void addListener (ConnectionListener *listener)
 Add a listener for connection state changes.
void removeListener (ConnectionListener *listener)
 Remove a listener for connection state changes.

Static Public Member Functions

static ConnectionPtr create (ConnectionDescriptionPtr description)
 Creates a new connection.

Protected Member Functions

Input/Output
virtual int64_t read (void *buffer, const uint64_t bytes)=0
 Read data from the connection.
virtual int64_t write (const void *buffer, const uint64_t bytes) const =0
 Write data to the connection.

Member Typedef Documentation

Returns:
the notifier handle to signal that data can be read.

Definition at line 253 of file connection.h.


Member Function Documentation

ConnectionPtr eq::net::Connection::create ( ConnectionDescriptionPtr  description  )  [static]

Creates a new connection.

This factory method creates a new concrete connection for the requested type. The concrete connection may not support all functionality of the Connection interface.

Parameters:
description describing the connection to be created.
Returns:
the connection.

Definition at line 52 of file connection.cpp.

References eq::net::CONNECTIONTYPE_PIPE, eq::net::CONNECTIONTYPE_SDP, and eq::net::CONNECTIONTYPE_TCPIP.

Referenced by eq::net::Node::initConnect(), and eq::net::Node::listen().

Here is the caller graph for this function:

State eq::net::Connection::getState (  )  const [inline]

Returns the state of this connection.

Returns:
the state of this connection.

Definition at line 72 of file connection.h.

bool eq::net::Connection::isClosed (  )  const [inline]

Returns:
true if the connection is in the closed state.

Definition at line 75 of file connection.h.

bool eq::net::Connection::isConnected (  )  const [inline]

Returns:
true if the connection is in the connected state.

Definition at line 78 of file connection.h.

bool eq::net::Connection::isListening (  )  const [inline]

Returns:
true if the connection is in the listening state.

Definition at line 81 of file connection.h.

void eq::net::Connection::setDescription ( ConnectionDescriptionPtr  description  ) 

Set the connection's description.

Parameters:
description the connection parameters.

Definition at line 394 of file connection.cpp.

References eq::base::RefPtr< T >::isValid().

Here is the call graph for this function:

ConnectionDescriptionPtr eq::net::Connection::getDescription (  )  const

Returns:
the description for this connection.

Definition at line 389 of file connection.cpp.

virtual bool eq::net::Connection::connect (  )  [inline, virtual]

Connect to the remote peer.

Returns:
true if the connection was successfully connected, false if not.

Reimplemented in eq::net::PairConnection, eq::net::PipeConnection, and eq::net::SocketConnection.

Definition at line 102 of file connection.h.

virtual bool eq::net::Connection::listen (  )  [inline, virtual]

Put the connection into the listening state for a new incoming connection.

Returns:
true if the connection is listening for new incoming connections, false if not.

Reimplemented in eq::net::SocketConnection.

Definition at line 111 of file connection.h.

virtual ConnectionPtr eq::net::Connection::accept (  )  [inline, virtual]

Accepts the next incoming connection.

Returns:
the accepted connection, or an invalid pointer if no connection was accepted.

Reimplemented in eq::net::SocketConnection.

Definition at line 119 of file connection.h.

Referenced by accept().

Here is the caller graph for this function:

ConnectionPtr eq::net::Connection::accept ( const int  timeout  )  [virtual]

Accepts the next incoming connection with a timeout.

Parameters:
timeout the amount of time to wait in milliseconds, if set to -1 the method blocks indefinitely.
Returns:
the accepted connection, or an invalid pointer if no connection was accepted.

Definition at line 75 of file connection.cpp.

References _state, and accept().

Here is the call graph for this function:

void eq::net::Connection::addListener ( ConnectionListener listener  ) 

Add a listener for connection state changes.

Definition at line 121 of file connection.cpp.

References _listeners.

void eq::net::Connection::removeListener ( ConnectionListener listener  ) 

Remove a listener for connection state changes.

Definition at line 126 of file connection.cpp.

References _listeners.

bool eq::net::Connection::recv ( void *  buffer,
const uint64_t  bytes 
)

Read data from the connection.

Parameters:
buffer the buffer for saving the message.
bytes the number of bytes to read.
Returns:
true if all data has been read, false if not.

Definition at line 147 of file connection.cpp.

References _state, eq::base::disableFlush(), eq::base::enableFlush(), and read().

Here is the call graph for this function:

void eq::net::Connection::lockSend (  )  const [inline]

Lock the connection, no other thread can send data.

Definition at line 159 of file connection.h.

Referenced by send().

Here is the caller graph for this function:

void eq::net::Connection::unlockSend (  )  const [inline]

Unlock the connection.

Definition at line 161 of file connection.h.

Referenced by send().

Here is the caller graph for this function:

bool eq::net::Connection::send ( const void *  buffer,
const uint64_t  bytes,
const bool  isLocked = false 
) const

Sends data using the connection.

Parameters:
buffer the buffer containing the message.
bytes the number of bytes to send.
isLocked true if the connection is locked externally.
Returns:
true if all data has been read, false if not.

Definition at line 218 of file connection.cpp.

References _state, eq::base::disableFlush(), eq::base::enableFlush(), and write().

Referenced by send(), eq::net::ObjectInstanceDataOStream::sendBuffer(), eq::net::ObjectDeltaDataOStream::sendBuffer(), eq::net::ObjectInstanceDataOStream::sendFooter(), and eq::net::ObjectDeltaDataOStream::sendFooter().

Here is the call graph for this function:

Here is the caller graph for this function:

bool eq::net::Connection::send ( const Packet packet  )  const [inline]

Sends a packaged message using the connection.

Parameters:
packet the message packet.
Returns:
true if all data has been read, false if not.

Definition at line 180 of file connection.h.

References eq::net::Packet::size.

bool eq::net::Connection::send ( Packet packet,
const std::string &  string 
) const [inline]

Sends a packaged message including a string using the connection.

Parameters:
packet the message packet.
string the string.
Returns:
true if all data has been read, false if not.

Definition at line 190 of file connection.h.

template<typename T>
bool eq::net::Connection::send ( Packet packet,
const std::vector< T > &  data 
) const [inline]

Sends a packaged message including additional data.

The last item of the packet has to be able to hold one item or eight bytes of the data, whatever is bigger.

Parameters:
packet the message packet.
data the vector containing the data.
Returns:
true if all data has been read, false if not.

Definition at line 315 of file connection.h.

bool eq::net::Connection::send ( Packet packet,
const void *  data,
const uint64_t  size 
) const

Sends a packaged message including additional data using the connection.

Parameters:
packet the message packet.
data the data.
size the data size in bytes.
Returns:
true if all data has been read, false if not.

Definition at line 281 of file connection.cpp.

References lockSend(), send(), eq::net::Packet::size, and unlockSend().

Here is the call graph for this function:

bool eq::net::Connection::send ( const ConnectionVector &  connections,
const Packet packet,
const bool  isLocked = false 
) [static]

Sends a packaged message to multiple connections.

Parameters:
connections The connections.
packet the message packet.
isLocked true if the connection is locked externally.
Returns:
true if the packet was sent successfully to all connections.

Definition at line 318 of file connection.cpp.

References eq::net::Packet::size.

bool eq::net::Connection::send ( const ConnectionVector &  connections,
Packet packet,
const void *  data,
const uint64_t  size,
const bool  isLocked = false 
) [static]

Sends a packaged message including additional data to multiple connections.

Parameters:
connections The connections.
packet the message packet.
data the data.
size the data size in bytes.
isLocked true if the connection is locked externally.
Returns:
true if the packet was sent successfully to all receivers.

Definition at line 333 of file connection.cpp.

References send(), and eq::net::Packet::size.

Here is the call graph for this function:

virtual int64_t eq::net::Connection::read ( void *  buffer,
const uint64_t  bytes 
) [protected, pure virtual]

Read data from the connection.

Note the the a return value of 0 is not an error condition, it means that no data was pending on a non-blocking connection.

Parameters:
buffer the buffer for saving the message.
bytes the number of bytes to read.
Returns:
the number of bytes read, or -1 upon error.

Implemented in eq::net::BufferConnection, eq::net::FDConnection, and eq::net::PairConnection.

Referenced by recv().

Here is the caller graph for this function:

virtual int64_t eq::net::Connection::write ( const void *  buffer,
const uint64_t  bytes 
) const [protected, pure virtual]

Write data to the connection.

Parameters:
buffer the buffer containing the message.
bytes the number of bytes to write.
Returns:
the number of bytes written, or -1 upon error.

Implemented in eq::net::BufferConnection, eq::net::FDConnection, and eq::net::PairConnection.

Referenced by send().

Here is the caller graph for this function:


The documentation for this class was generated from the following files:
Generated on Sat Dec 6 12:01:51 2008 for Equalizer 0.6 by  doxygen 1.5.5