plumbing::endpoint_client Class Reference

#include <client.h>

Inheritance diagram for plumbing::endpoint_client:
plumbing::endpoint plumbing::endpoint_client_stdout

Public Member Functions

virtual ~endpoint_client ()
void write (const std::string &text)
bool more_to_send () const
bool is_connected () const
int get_port () const
const std::string & get_host () const

Protected Member Functions

 endpoint_client (const std::string &hostname, int port)
 endpoint_client (const std::string &hostname, const std::string &port)
int get_read_file_descriptor ()
void process_read ()
int get_write_file_descriptor ()
void process_write ()
virtual void data_received (const void *data, size_t nbytes)=0

Private Types

typedef std::deque< std::string > write_queue_t

Private Member Functions

void try_to_connect ()
 endpoint_client ()
 endpoint_client (const endpoint_client &)
endpoint_clientoperator= (const endpoint_client &)

Private Attributes

std::string hostname
int port
void * sock_addr
int sock_addr_size
bool connecting
time_t retry_after
write_queue_t write_queue

Detailed Description

The plumbing::endpoint_client class is used to represent a simple text based client, which is able to write to a server and prints all responses from the server on the standard output.

Definition at line 33 of file client.h.


Member Typedef Documentation

typedef std::deque<std::string> plumbing::endpoint_client::write_queue_t [private]

The write_queue_t typedef describes the type of the write_queue instance variable. It doesn't include the word "deque" or "vector" so that its implementation may change in the future, and this is the only place which will need editing.

Definition at line 184 of file client.h.


Constructor & Destructor Documentation

plumbing::endpoint_client::~endpoint_client (  )  [virtual]

The destructor.

Definition at line 38 of file client.cc.

plumbing::endpoint_client::endpoint_client ( const std::string &  hostname,
int  port 
) [protected]

A constructor. It is protected on purpose, you must derive from this class.

Parameters:
hostname The name of the remote host. May be a dotted-quad or a string to be looked-up via gethostbyname.
port The port number.

Definition at line 44 of file client.cc.

plumbing::endpoint_client::endpoint_client ( const std::string &  hostname,
const std::string &  port 
) [protected]

A constructor. It is protected on purpose, you must derive from this class.

Parameters:
hostname The name of the remote host. May be a dotted-quad or a string to be looked-up via gethostbyname.
port The port number. May be a string service name ("ssh") or a numeric port number ("22").

Definition at line 61 of file client.cc.

plumbing::endpoint_client::endpoint_client (  )  [private]

The default constructor. Do not use.

plumbing::endpoint_client::endpoint_client ( const endpoint_client  )  [private]

The copy constructor. Do not use.


Member Function Documentation

virtual void plumbing::endpoint_client::data_received ( const void *  data,
size_t  nbytes 
) [protected, pure virtual]

The data_received method is called by process_read whenever new data arrived from the server.

Parameters:
data The data from the server
nbytes The size of the data from the server. This will be zero when the remote server closes the connection.

Implemented in plumbing::endpoint_client_stdout.

const std::string& plumbing::endpoint_client::get_host (  )  const [inline]

The get_host method may be used to obtain the name of the host the client is connected to, or will attempt to connect to.

Definition at line 113 of file client.h.

int plumbing::endpoint_client::get_port (  )  const [inline]

The get_port method may be used to obtain the port number the client is connected to, or will attempt to connect to.

Returns:
the port number (1 to 65535)

Definition at line 107 of file client.h.

int plumbing::endpoint_client::get_read_file_descriptor (  )  [protected, virtual]

The get_read_file_descriptor method is used to obtain the file descriptor that select is to wait upon for read events. The default implementation returns the fd instance variable.

Returns:
int; >=0 for a valid file descriptior, or -1 if read events should not be waited for.
Note:
DO NOT close the file descriptor and set it to -1 in this method. Do that in the process_read method instead, otherwise you confuse the select() processing.

Reimplemented from plumbing::endpoint.

Definition at line 217 of file client.cc.

int plumbing::endpoint_client::get_write_file_descriptor (  )  [protected, virtual]

The get_write_file_descriptor method is used to obtain the file descriptor that select is to wait upon for write events. The default implementation returns -1.

Returns:
int; >=0 for a valid file descriptior, or -1 if write events should not be waited for.
Note:
This method need not returns the same file descriptor as returned by the get_read_file_descriptor method. You could, for example, use dup(2) to separate the two.
DO NOT close the file descriptor and set it to -1 in this method. Do that in the process_write method instead, otherwise you confuse the select() processing.

Reimplemented from plumbing::endpoint.

Definition at line 96 of file client.cc.

bool plumbing::endpoint_client::is_connected (  )  const [inline]

The is_connected method may be used to determine whether or not the client is connected to its server or not.

Returns:
true if connected to server, or false if not connected.

Definition at line 98 of file client.h.

bool plumbing::endpoint_client::more_to_send (  )  const [inline]

The more_to_send method may be used to determine whether or not the write queue is not empty, that there is still more to send.

Definition at line 89 of file client.h.

endpoint_client& plumbing::endpoint_client::operator= ( const endpoint_client  )  [private]

The assignment operator. Do not use.

void plumbing::endpoint_client::process_read (  )  [protected, virtual]

The process_read method is called by the select loop when a readable event is detected on the read file descriptor.

Implements plumbing::endpoint.

Definition at line 227 of file client.cc.

void plumbing::endpoint_client::process_write (  )  [protected, virtual]

The process_write method is called by the select loop when a writable event is detected on the read file descriptor.

Implements plumbing::endpoint.

Definition at line 106 of file client.cc.

void plumbing::endpoint_client::try_to_connect (  )  [private]

The try_to_connect method is used to attempt to the server, if the connection is not currently open.

Definition at line 268 of file client.cc.

void plumbing::endpoint_client::write ( const std::string &  text  ) 

The write method may be used to write the given text to the server. A new line will be appended. The requests will be queued until the connection is established, and then sent when the server is able to accept them.

Note:
This method does not block. It returns immediately. If you are expecting a response from the server, the data_received() method will be called when it arrives.

There is no blocking write method. There is no blocking read method.

Definition at line 89 of file client.cc.


Field Documentation

The connecting instance variable is used to remember whether we are waiting for a non-blocking connect to complete, or not.

Definition at line 170 of file client.h.

std::string plumbing::endpoint_client::hostname [private]

The hostname instance variable is used to remember which host we are to connect to.

Definition at line 145 of file client.h.

The port instance variable is used to remember which port on the host we are to connect to.

Definition at line 151 of file client.h.

The retry_after instance variable is used to remember when to next retry the connect() to the server.

Definition at line 176 of file client.h.

The sock_addr instance variable is used to remember the dynamically allocated socket address object. It is void* rather than drag in all of the <sys/socket.h> baggage.

Definition at line 158 of file client.h.

The sock_addr_size instance variable is used to remember the size of the dynamically allocated socket address object.

Definition at line 164 of file client.h.

The write_queue instance variable is used to remember the queue of lines waiting to be sent to the server. This queue may be because the connection has not completed yet, or because previous packets are still being sent.

Definition at line 192 of file client.h.


The documentation for this class was generated from the following files:
Generated on Thu Sep 16 14:51:27 2010 for Plumbing by  doxygen 1.6.3