iodrivers_base
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
iodrivers_base::TCPDriver Class Reference

#include <TCPDriver.hpp>

Inheritance diagram for iodrivers_base::TCPDriver:
iodrivers_base::Driver

Public Member Functions

 TCPDriver (int max_packet_size, bool extract_last=false)
 
virtual ~TCPDriver ()
 
void tcp_server_init (int port)
 
virtual int readPacket (uint8_t *buffer, int bufsize)
 
virtual int readPacket (uint8_t *buffer, int bufsize, base::Time const &packet_timeout, base::Time const &first_byte_timeout)
 
virtual bool writePacket (uint8_t const *buffer, int bufsize, base::Time const &timeout)
 
bool hasOpenSocked () const
 
- Public Member Functions inherited from iodrivers_base::Driver
 Driver (int max_packet_size, bool extract_last=false)
 
virtual ~Driver ()
 
void setReadTimeout (base::Time const &t)
 
base::Time getReadTimeout () const
 
void setWriteTimeout (base::Time const &t)
 
base::Time getWriteTimeout () const
 
void clear ()
 
Status getStatus () const
 
void resetStatus ()
 
Status getStats () const
 
void resetStats ()
 
void setExtractLastPacket (bool flag)
 
bool getExtractLastPacket () const
 
virtual void openURI (std::string const &uri)
 
bool openInet (const char *hostname, int port)
 
void openTCP (std::string const &hostname, int port)
 
void openUDP (std::string const &hostname, int remote_port)
 
void openUDPBidirectional (std::string const &hostname, int out_port, int in_port)
 
bool openSerial (std::string const &port, int baudrate)
 
void openFile (std::string const &path)
 
void setFileDescriptor (int fd, bool auto_close=true)
 
int getFileDescriptor () const
 
bool isValid () const
 
bool setSerialBaudrate (int rate)
 
virtual void close ()
 
bool hasPacket () const
 
int readPacket (uint8_t *buffer, int bufsize)
 
int readPacket (uint8_t *buffer, int bufsize, base::Time const &packet_timeout)
 
int readPacket (uint8_t *buffer, int bufsize, int packet_timeout, int first_byte_timeout=-1)
 
int readPacket (uint8_t *buffer, int bufsize, base::Time const &packet_timeout, base::Time const &first_byte_timeout)
 
bool writePacket (uint8_t const *buffer, int bufsize)
 
bool writePacket (uint8_t const *buffer, int bufsize, int timeout)
 
bool writePacket (uint8_t const *buffer, int bufsize, base::Time const &timeout)
 
virtual int extractPacket (uint8_t const *buffer, size_t buffer_size) const =0
 
void setMainStream (IOStream *stream)
 
IOStreamgetMainStream () const
 
void openTestMode ()
 
void addListener (IOListener *stream)
 
void removeListener (IOListener *stream)
 

Protected Member Functions

virtual void checkClientConnection ()
 
- Protected Member Functions inherited from iodrivers_base::Driver
std::pair< int, bool > readPacketInternal (uint8_t *buffer, int bufsize)
 
std::pair< uint8_t const *, int > findPacket (uint8_t const *buffer, int buffer_size) const
 
std::pair< int, bool > extractPacketFromInternalBuffer (uint8_t *buffer, int out_buffer_size)
 
int doPacketExtraction (uint8_t *buffer)
 
void openIPClient (std::string const &hostname, int port, addrinfo const &hints)
 

Protected Attributes

int socked_fd
 
int client_fd
 
struct sockaddr_in cli_addr
 
socklen_t clilen
 
- Protected Attributes inherited from iodrivers_base::Driver
IOStreamm_stream
 
std::set< IOListener * > m_listeners
 
bool m_auto_close
 
bool m_extract_last
 
base::Time m_read_timeout
 
base::Time m_write_timeout
 
Status m_stats
 

Additional Inherited Members

- Public Types inherited from iodrivers_base::Driver
enum  SERIAL_RATES {
  SERIAL_1200 = 1200, SERIAL_2400 = 2400, SERIAL_4800 = 4800, SERIAL_9600 = 9600,
  SERIAL_19200 = 19200, SERIAL_38400 = 38400, SERIAL_57600 = 57600, SERIAL_115200 = 115200,
  SERIAL_230400 = 230400, SERIAL_460800 = 460800, SERIAL_576000 = 576000, SERIAL_921600 = 921600,
  SERIAL_1152000 = 1152000
}
 
typedef iodrivers_base::Status Statistics
 
- Static Public Member Functions inherited from iodrivers_base::Driver
static int openSerialIO (std::string const &port, int baudrate)
 
static bool setNonBlockingFlag (int fd)
 
static bool setSerialBaudrate (int fd, int rate)
 
static std::string printable_com (std::string const &buffer)
 
static std::string printable_com (uint8_t const *buffer, size_t buffer_size)
 
static std::string printable_com (char const *buffer, size_t buffer_size)
 
static std::string binary_com (std::string const &str)
 
static std::string binary_com (uint8_t const *str, size_t str_size)
 
static std::string binary_com (char const *str, size_t str_size)
 
- Public Attributes inherited from iodrivers_base::Driver
int const MAX_PACKET_SIZE
 
- Static Public Attributes inherited from iodrivers_base::Driver
static const int INVALID_FD = -1
 

Detailed Description

This class implements an TCP Server for single Client If more thn one client tryes to connect, the old one is disconnected see checkClientConnection for more details or if you want to implement support for more than one client

Constructor & Destructor Documentation

iodrivers_base::TCPDriver::TCPDriver ( int  max_packet_size,
bool  extract_last = false 
)
iodrivers_base::TCPDriver::~TCPDriver ( )
virtual

Member Function Documentation

void iodrivers_base::TCPDriver::checkClientConnection ( )
protectedvirtual

This Method cheks for an new waiting client that tryes to connect to the current port. If an new clienet is discoverd, the old one will be disconnected and an connection to the new one is established The new fiile descriptor is passed to the iodriver to now handle the connection to the new one the old one is closed so that the old client will be disconnected

bool iodrivers_base::TCPDriver::hasOpenSocked ( ) const
inline
int iodrivers_base::TCPDriver::readPacket ( uint8_t *  buffer,
int  bufsize 
)
virtual

Overloaded method from iodriver_base::Driver, additionally calls checkClientConntion();

int iodrivers_base::TCPDriver::readPacket ( uint8_t *  buffer,
int  bufsize,
base::Time const &  packet_timeout,
base::Time const &  first_byte_timeout 
)
virtual
void iodrivers_base::TCPDriver::tcp_server_init ( int  port)

Initialized an new soked so that an TCP client can connect to the given port, connection is not established by this mehtod, you need to call read or write packed only one time to get the first connection.

bool iodrivers_base::TCPDriver::writePacket ( uint8_t const *  buffer,
int  bufsize,
base::Time const &  timeout 
)
virtual

Overloaded method from iodriver_base::Driver, additionally calls checkClientConntion();

Member Data Documentation

struct sockaddr_in iodrivers_base::TCPDriver::cli_addr
protected

Internal members to handle the connection

int iodrivers_base::TCPDriver::client_fd
protected
socklen_t iodrivers_base::TCPDriver::clilen
protected

Internal members to handle the connection

int iodrivers_base::TCPDriver::socked_fd
protected

Corresponding file descriptor to the socked


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