#include <fdconnector.h>
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 Data * | read () |
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. |
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.
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.
FDConnector::FDConnector | ( | ) | [protected] |
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.
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().
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.
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().
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().
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().
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().
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().