FDConnector Class Reference
[Connector implementation classes and data]

FDConnector is an implementation of Connector that handles I/O and close events on a simple file descriptor. More...

#include <fdconnector.h>

Inheritance diagram for FDConnector:

Inheritance graph
[legend]
Collaboration diagram for FDConnector:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 FDConnector (int)
 Instantiate a new FDConnector with an already-open (and connected) fd.
virtual ~FDConnector ()
virtual void disconnect ()
 Close the underlying fd.
virtual Dataread ()
 Read a blob of data from the underlying fd.
virtual ssize_t write (const Data &b)
 Write a blob of data to the underlying fd.
virtual std::string get_id () const
 Instance identification string (abstract virtual).
virtual bool connected (void) const
 Returns whether this FDConnector is currently connected.

Protected Member Functions

 FDConnector ()
virtual void connect (int fd)
 Used by subclasses to set up the fd.

Private Attributes

int fd
 This is the fd that we're connected to (protected by mutex).
pthread_mutex_t mutex
 The mutex we use to protect changes to fd.


Detailed Description

FDConnector is an implementation of Connector that handles I/O and close events on a simple file descriptor.

It provides the minimum functionality required of a Connector. In particular, it holds no address information, and so it is unable to open an initial connection of any form (since it wouldn't make any sense to connect random fd, anyway), and therefore has no ability to re-connect when closed.

Instantiate an FDConnector by passing an open fd to the constructor. You may then use the FDConnector to read and write on that fd, and you can close the Connector by calling disconnect(). If the fd is closed by an external entity (such as when the fd is a socket, and the other side disconnects), the "owner" Messageable will be sent a Message indicating that closure. The FDConnector will not allow reading and writing after the fd is closed, so all you can really do at that point is delete it. When you are done with the FDConnector, you should delete it, which close the fd if it is still open.

Note:
We still need to decide if we want a separate notify_on_disconnect() method, or if that argument should be passed to the constructor, or if we want to add a public connect() method that takes it. We also still need to decide whether disconnection notification messages should be sent to the owner when disconnect() or the destructor are called explicitly on an open connection. I tend to think so.

This class should likely have two fd's (one for reading, one for writing) so that TTYConnector can be a subclass of it and still perform its current functionality.

Geoff doesn't currently agree; TTYConnector's use seems more like the special case, and adding that to FDConnector might make it more complicated than it needs to be for every other use. Still, this might be a win. Unsure.

Definition at line 82 of file fdconnector.h.


Constructor & Destructor Documentation

FDConnector::FDConnector (  )  [protected]

Definition at line 62 of file fdconnector.cc.

References mutex, and PTHREAD_CHECK_AND_THROW.

FDConnector::FDConnector ( int  the_fd  ) 

Instantiate a new FDConnector with an already-open (and connected) fd.

Definition at line 70 of file fdconnector.cc.

References mutex, and PTHREAD_CHECK_AND_THROW.

FDConnector::~FDConnector ( void   )  [virtual]

Definition at line 78 of file fdconnector.cc.

References disconnect(), and mutex.

Here is the call graph for this function:


Member Function Documentation

void FDConnector::disconnect ( void   )  [virtual]

Close the underlying fd.

This function will disconnect the socket connection, and return.

There is nothing more you can do with this objet afterward.

Implements Connector.

Reimplemented in LogFile.

Definition at line 130 of file fdconnector.cc.

References connected(), fd, and mutex.

Referenced by read(), write(), and ~FDConnector().

Here is the call graph for this function:

Here is the caller graph for this function:

Data * FDConnector::read (  )  [virtual]

Read a blob of data from the underlying fd.

Implements Connector.

Definition at line 156 of file fdconnector.cc.

References Connector::BufSize, disconnect(), and fd.

Here is the call graph for this function:

ssize_t FDConnector::write ( const Data b  )  [virtual]

Write a blob of data to the underlying fd.

Implements Connector.

Definition at line 175 of file fdconnector.cc.

References Data::data(), disconnect(), fd, and Data::len().

Referenced by LogFile::connect(), and LogFile::disconnect().

Here is the call graph for this function:

Here is the caller graph for this function:

std::string FDConnector::get_id (  )  const [virtual]

Instance identification string (abstract virtual).

Implements Connector.

Reimplemented in LogFile, and SocketConnector.

Definition at line 97 of file fdconnector.cc.

References fd.

Referenced by SocketListener::listen_for_incoming().

Here is the caller graph for this function:

bool FDConnector::connected ( void   )  const [virtual]

Returns whether this FDConnector is currently connected.

This is called by Connection and friends, so should be a public method.

Implements Connector.

Definition at line 150 of file fdconnector.cc.

References fd.

Referenced by connect(), LogFile::disconnect(), and disconnect().

Here is the caller graph for this function:

void FDConnector::connect ( int  fd  )  [protected, virtual]

Used by subclasses to set up the fd.

Definition at line 115 of file fdconnector.cc.

References connected(), fd, and mutex.

Referenced by SocketConnector::connect(), and LogFile::connect().

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

int FDConnector::fd [private]

This is the fd that we're connected to (protected by mutex).

Contains the value -1 if we're not actually connected, such as after disconnect() is called.

Definition at line 124 of file fdconnector.h.

Referenced by LogFile::connect(), connect(), connected(), disconnect(), get_id(), read(), and write().

pthread_mutex_t FDConnector::mutex [private]

The mutex we use to protect changes to fd.

Definition at line 127 of file fdconnector.h.

Referenced by connect(), disconnect(), FDConnector(), and ~FDConnector().


The documentation for this class was generated from the following files:

Generated on Tue May 13 11:32:45 2008 for consmgr by  doxygen 1.5.5