cxxtools::net::TcpStream Class Reference

A buffered TCP/IP stream which supports asyncronous communication. More...

#include <cxxtools/net/tcpstream.h>

Inheritance diagram for cxxtools::net::TcpStream:
cxxtools::IOStream cxxtools::Connectable cxxtools::BasicIOStream< char > basic_iostream

Public Member Functions

 TcpStream (unsigned bufsize=0, cxxtools::Milliseconds timeout=Selectable::WaitInfinite)
 Creates a not connected TCP stream object.
 TcpStream (const std::string &ipaddr, unsigned short int port, unsigned bufsize=0, cxxtools::Milliseconds timeout=Selectable::WaitInfinite)
 Creates a TCP stream object and connects to the specified IP address and port.
 TcpStream (const AddrInfo &addrinfo, unsigned bufsize=0, cxxtools::Milliseconds timeout=Selectable::WaitInfinite)
 Creates a TCP stream object and connects to the specified address info.
 TcpStream (const char *ipaddr, unsigned short int port, unsigned bufsize=8192, cxxtools::Milliseconds timeout=Selectable::WaitInfinite)
 Creates a TCP stream object and connects to the specified IP address and port.
 TcpStream (TcpServer &server, unsigned bufsize=8192, unsigned flags=0, cxxtools::Milliseconds timeout=Selectable::WaitInfinite)
 Creates a TCP stream object and accepts a connection from a server.
void setTimeout (Milliseconds timeout)
 Set timeout to the given value in milliseconds.
Milliseconds getTimeout () const
 Returns the current value for timeout in milliseconds.
void close ()
bool beginConnect (const AddrInfo &addrinfo)
bool beginConnect (const std::string &ipaddr, unsigned short int port)
void endConnect ()
void connect (const AddrInfo &addrinfo)
void connect (const std::string &ipaddr, unsigned short int port)
void accept (const TcpServer &server, unsigned flags=0)
std::string getSockAddr () const
std::string getPeerAddr () const
bool isConnected () const
int getFd () const
void sslConnect ()
void sslAccept ()
void sslShutdown ()
TcpSocketsocket ()
- Public Member Functions inherited from cxxtools::IOStream
 IOStream (size_t bufferSize=8192, bool extend=false)
 IOStream (IODevice &device, size_t bufferSize=8192, bool extend=false)
 ~IOStream ()
StreamBufferbuffer ()
IODeviceattachDevice (IODevice &device)
IODeviceattachedDevice ()
- Public Member Functions inherited from cxxtools::BasicIOStream< char >
 BasicIOStream (BasicStreamBuffer< char > *buffer=0)
 ~BasicIOStream ()
BasicStreamBuffer< char > * attachedBuffer ()
 Access to the underlying buffer.
BasicStreamBuffer< char > * attachBuffer (BasicStreamBuffer< char > *buffer)
std::streamsize peeksome (char *buffer, std::streamsize n)
 Peeks bytes in the stream buffer.
std::streamsize writesome (char *buffer, std::streamsize n)
- Public Member Functions inherited from cxxtools::Connectable
 Connectable ()
 Default constructor.
virtual ~Connectable ()
 Closes all connections.
virtual void onConnectionOpen (const Connection &c)
 Registers a Connection with the Connectable.
virtual void onConnectionClose (const Connection &c)
 Unregisters a Connection from the Connectable.
size_t connectionCount () const

Public Attributes

Signal< TcpStream & > inputReady
 Notifies about available data.
Signal< TcpStream & > outputReady
 Notifies when data can be written.
Signal< TcpStream & > connected
 Notifies when the device is connected after beginConnect.
Signal< TcpStream & > closed
 Notifies when the device is closed while no reading or writing is pending.

Additional Inherited Members

- Protected Member Functions inherited from cxxtools::Connectable
 Connectable (const Connectable &)
 Copy constructor.
Connectableoperator= (const Connectable &)
 Assignment operator.
const std::list< Connection > & connections () const
 Returns a list of all current connections.
std::list< Connection > & connections ()
 Returns a list of all current connections.
void clear ()
- Protected Attributes inherited from cxxtools::Connectable
std::list< Connection_connections
 A list of all current connections.

Detailed Description

A buffered TCP/IP stream which supports asyncronous communication.

When a object is created a buffer size is passed. By default the buffer size is 0, which means, that the buffer is dynamically extended when needed so that writing do not block.

Constructor & Destructor Documentation

cxxtools::net::TcpStream::TcpStream ( unsigned  bufsize = 0,
cxxtools::Milliseconds  timeout = Selectable::WaitInfinite 
)
inlineexplicit

Creates a not connected TCP stream object.

cxxtools::net::TcpStream::TcpStream ( const std::string &  ipaddr,
unsigned short int  port,
unsigned  bufsize = 0,
cxxtools::Milliseconds  timeout = Selectable::WaitInfinite 
)
inline

Creates a TCP stream object and connects to the specified IP address and port.

cxxtools::net::TcpStream::TcpStream ( const AddrInfo addrinfo,
unsigned  bufsize = 0,
cxxtools::Milliseconds  timeout = Selectable::WaitInfinite 
)
inlineexplicit

Creates a TCP stream object and connects to the specified address info.

cxxtools::net::TcpStream::TcpStream ( const char *  ipaddr,
unsigned short int  port,
unsigned  bufsize = 8192,
cxxtools::Milliseconds  timeout = Selectable::WaitInfinite 
)
inline

Creates a TCP stream object and connects to the specified IP address and port.

cxxtools::net::TcpStream::TcpStream ( TcpServer server,
unsigned  bufsize = 8192,
unsigned  flags = 0,
cxxtools::Milliseconds  timeout = Selectable::WaitInfinite 
)
inlineexplicit

Creates a TCP stream object and accepts a connection from a server.

Member Function Documentation

void cxxtools::net::TcpStream::accept ( const TcpServer server,
unsigned  flags = 0 
)
inline
bool cxxtools::net::TcpStream::beginConnect ( const AddrInfo addrinfo)
inline
bool cxxtools::net::TcpStream::beginConnect ( const std::string &  ipaddr,
unsigned short int  port 
)
inline
void cxxtools::net::TcpStream::close ( )
inline
void cxxtools::net::TcpStream::connect ( const AddrInfo addrinfo)
inline
void cxxtools::net::TcpStream::connect ( const std::string &  ipaddr,
unsigned short int  port 
)
inline
void cxxtools::net::TcpStream::endConnect ( )
inline
int cxxtools::net::TcpStream::getFd ( ) const
inline
std::string cxxtools::net::TcpStream::getPeerAddr ( ) const
inline
std::string cxxtools::net::TcpStream::getSockAddr ( ) const
inline
Milliseconds cxxtools::net::TcpStream::getTimeout ( ) const
inline

Returns the current value for timeout in milliseconds.

bool cxxtools::net::TcpStream::isConnected ( ) const
inline
void cxxtools::net::TcpStream::setTimeout ( Milliseconds  timeout)
inline

Set timeout to the given value in milliseconds.

TcpSocket& cxxtools::net::TcpStream::socket ( )
inline
void cxxtools::net::TcpStream::sslAccept ( )
inline
void cxxtools::net::TcpStream::sslConnect ( )
inline
void cxxtools::net::TcpStream::sslShutdown ( )
inline

Member Data Documentation

Signal<TcpStream&> cxxtools::net::TcpStream::closed

Notifies when the device is closed while no reading or writing is pending.

Signal<TcpStream&> cxxtools::net::TcpStream::connected

Notifies when the device is connected after beginConnect.

Signal<TcpStream&> cxxtools::net::TcpStream::inputReady

Notifies about available data.

This signal is send when the Socket is monitored in a Selector or EventLoop and data becomes available.

The system must call beginRead() to monitor the tcpstream for reading. After the signal is received, data is available in the stream or in case of disconnection, reading fails.

Signal<TcpStream&> cxxtools::net::TcpStream::outputReady

Notifies when data can be written.

This signal is send when the Socket is monitored in a Selector or EventLoop and the device is ready to write data.


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