TCP connection as a std::iostream.
More...
#include <tcpStream.hpp>
Public Member Functions | |
| TcpStream (const std::string &host, uint16_t port, std::size_t bufSize=DEFAULT_BUFFER_SIZE) | |
| TcpStream (anch::network::Socket &&socket, std::size_t bufSize=DEFAULT_BUFFER_SIZE) | |
| TcpStream (const TcpStream &)=delete | |
| TcpStream (TcpStream &&)=delete | |
| virtual | ~TcpStream () noexcept |
| void | shutdown (anch::network::Direction how=anch::network::Direction::TRANSMISSION) |
| anch::network::Socket & | getSocket () noexcept |
| Public Member Functions inherited from anch::cutils::CIOStream | |
| CIOStream (const anch::cutils::cbuffer &cbuffer) | |
| virtual | ~CIOStream () |
Static Public Attributes | |
| static constexpr std::size_t | DEFAULT_BUFFER_SIZE = 8192 |
Additional Inherited Members | |
| Protected Member Functions inherited from anch::cutils::CIOStream | |
| CIOStream () | |
| void | setBuffer (const anch::cutils::cbuffer &cbuffer) |
TCP connection as a std::iostream.
Written data are buffered: they are sent when the buffer is full, on flush (or std::endl ), before reading (request / response protocols do not need an explicit flush) and on destruction.
End of stream (eof ) is reached when the peer has closed the connection (or shut down its transmission). Network errors set badbit ; with exceptions(std::ios::badbit) , the IOException is raised.
TcpStream can not be copied nor moved: it is built from a host and a port (client) or from a connected Socket (TcpServer::accept ).
| anch::network::TcpStream::TcpStream | ( | const std::string & | host, |
| uint16_t | port, | ||
| std::size_t | bufSize = DEFAULT_BUFFER_SIZE ) |
TcpStream constructor: connect to remote host
| host | the remote host name or numeric address (empty for loopback) |
| port | the remote port |
| bufSize | the buffer size |
| anch::network::IOException | connection error |
|
explicit |
TcpStream constructor: use a connected socket
| socket | the connected socket |
| bufSize | the buffer size |
|
delete |
|
delete |
Forbids TcpStream move constructor (the stream buffer refers to the socket)
|
virtualnoexcept |
TcpStream destructor: send pending data and close the connection
|
noexcept |
Socket getter (for options, addresses, ...)
| void anch::network::TcpStream::shutdown | ( | anch::network::Direction | how = anch::network::Direction::TRANSMISSION | ) |
Shut down part of the connection. Pending data are sent before shutting down transmission: the peer reaches the end of stream once it has read them, and this stream can still read the response.
| how | the direction to shut down |
| anch::network::IOException | error on shutdown |
|
staticconstexpr |
Default buffer size (for reading and for writing)