ucommon
7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
![]() ![]() |
#include <stream.h>
Public Member Functions | |
tcpstream (const tcpstream ©) | |
tcpstream (const TCPServer *server, unsigned segsize=536, timeout_t timeout=0) | |
tcpstream (int family=PF_INET, timeout_t timeout=0) | |
tcpstream (Socket::address &address, unsigned segsize=536, timeout_t timeout=0) | |
virtual | ~tcpstream () |
operator bool () const | |
bool | operator! () const |
void | open (Socket::address &address, unsigned segment=536) |
void | open (const char *host, const char *service, unsigned segment=536) |
void | close (void) |
![]() | |
int | sync (void) |
bool | is_open (void) const |
operator bool () const | |
bool | operator! () const |
Protected Member Functions | |
virtual ssize_t | _read (char *buffer, size_t size) |
virtual ssize_t | _write (const char *buffer, size_t size) |
virtual bool | _wait (void) |
void | release (void) |
int | underflow (void) __OVERRIDE |
int | overflow (int ch) __OVERRIDE |
socket_t | getsocket (void) const |
![]() | |
StreamBuffer () | |
int | uflow () __OVERRIDE |
void | release (void) |
void | allocate (size_t size) |
Protected Attributes | |
socket_t | so |
timeout_t | timeout |
![]() | |
size_t | bufsize |
char * | gbuf |
char * | pbuf |
Private Member Functions | |
__LOCAL void | allocate (unsigned size) |
__LOCAL void | reset (void) |
Streamable tcp connection between client and server. The tcp stream class can represent a client connection to a server or an instance of a service generated by a tcp listener. As a stream class, data can be manipulated using the << and >> operators.
ucommon::tcpstream::tcpstream | ( | const tcpstream & | copy | ) |
Copy constructor...
copy | for object. |
Definition at line 126 of file stream.cpp.
References ucommon::copy(), ucommon::Socket::create(), ucommon::Socket::family(), so, and timeout.
ucommon::tcpstream::tcpstream | ( | const TCPServer * | server, |
unsigned | segsize = 536 , |
||
timeout_t | timeout = 0 |
||
) |
Create a stream from an existing tcp listener.
server | to accept connection from. |
segsize | for tcp segments and buffering. |
timeout | for socket i/o operations. |
Definition at line 148 of file stream.cpp.
References ucommon::ListenSocket::accept(), allocate(), ucommon::clear(), INVALID_SOCKET, so, and timeout.
ucommon::tcpstream::tcpstream | ( | int | family = PF_INET , |
timeout_t | timeout = 0 |
||
) |
Create an unconnected tcp stream object that is idle until opened.
family | of protocol to create. |
timeout | for socket i/o operations. |
Definition at line 133 of file stream.cpp.
References ucommon::Socket::create(), so, and timeout.
ucommon::tcpstream::tcpstream | ( | Socket::address & | address, |
unsigned | segsize = 536 , |
||
timeout_t | timeout = 0 |
||
) |
A convenience constructor that creates a connected tcp stream directly from an address. The socket is constructed to match the type of the the address family in the socket address that is passed.
address | of service to connect to. |
segsize | for tcp segments and buffering. |
timeout | for socket i/o operations. |
Definition at line 140 of file stream.cpp.
References ucommon::Socket::create(), ucommon::Socket::address::family(), open(), so, and timeout.
|
virtual |
|
protectedvirtual |
Reimplemented in ucommon::sstream.
Definition at line 183 of file stream.cpp.
References buffer, MSG_WAITALL, ucommon::Socket::recvfrom(), and so.
Referenced by ucommon::sstream::_read(), and underflow().
|
protectedvirtual |
Reimplemented in ucommon::sstream.
Definition at line 175 of file stream.cpp.
References so, timeout, and ucommon::Socket::wait().
Referenced by ucommon::sstream::_wait(), and underflow().
|
protectedvirtual |
Reimplemented in ucommon::sstream.
Definition at line 188 of file stream.cpp.
References buffer, ucommon::Socket::sendto(), and so.
Referenced by ucommon::sstream::_write(), and overflow().
|
private |
Definition at line 353 of file stream.cpp.
References ucommon::StreamBuffer::allocate(), ucommon::StreamBuffer::bufsize, ucommon::max(), ucommon::Socket::recvsize(), ucommon::Socket::sendsize(), ucommon::Socket::sendwait(), and so.
Referenced by open(), and tcpstream().
void ucommon::tcpstream::close | ( | void | ) |
Close an active stream connection. This does not release the socket but is a disconnect.
Definition at line 334 of file stream.cpp.
References ucommon::StreamBuffer::bufsize, ucommon::clear(), ucommon::Socket::disconnect(), ucommon::StreamBuffer::gbuf, ucommon::StreamBuffer::pbuf, so, and ucommon::StreamBuffer::sync().
Referenced by ucommon::sstream::close(), and open().
|
inlineprotected |
void ucommon::tcpstream::open | ( | const char * | host, |
const char * | service, | ||
unsigned | segment = 536 |
||
) |
Open a stream connectoion to a host and service.
host | to connect to. |
service | to connect to by name or number as string. |
segment | buffering size to use. |
Definition at line 299 of file stream.cpp.
References allocate(), ucommon::StreamBuffer::bufsize, close(), ucommon::Socket::connectto(), ucommon::Socket::query(), ucommon::Socket::release(), and so.
void ucommon::tcpstream::open | ( | Socket::address & | address, |
unsigned | segment = 536 |
||
) |
Open a stream connection to a tcp service.
address | of service to access. |
segment | buffering size to use. |
Definition at line 288 of file stream.cpp.
References allocate(), ucommon::StreamBuffer::bufsize, close(), ucommon::Socket::connectto(), and so.
Referenced by ucommon::sstream::open(), and tcpstream().
|
inline |
See if stream connection is active.
Definition at line 196 of file stream.h.
References INVALID_SOCKET.
|
inline |
See if stream is disconnected.
Definition at line 204 of file stream.h.
References INVALID_SOCKET.
|
protected |
This streambuf method is used to write the output buffer through the established tcp connection.
ch | char to push through. |
Definition at line 240 of file stream.cpp.
References _write(), ucommon::StreamBuffer::bufsize, ch, EOF, IS_EOF, ucommon::StreamBuffer::pbuf, PUT, and reset().
|
protected |
Release the tcp stream and destroy the underlying socket.
Definition at line 165 of file stream.cpp.
References ucommon::StreamBuffer::release(), ucommon::Socket::release(), and so.
Referenced by ~tcpstream().
|
private |
Definition at line 317 of file stream.cpp.
References ucommon::StreamBuffer::bufsize, ucommon::clear(), ucommon::Socket::disconnect(), ucommon::StreamBuffer::gbuf, ucommon::StreamBuffer::pbuf, and so.
Referenced by overflow(), and underflow().
|
protected |
This streambuf method is used to load the input buffer through the established tcp socket connection.
Definition at line 193 of file stream.cpp.
References _read(), _wait(), ucommon::StreamBuffer::bufsize, ch, ucommon::clear(), EOF, ucommon::StreamBuffer::gbuf, GET, and reset().
|
protected |
Definition at line 121 of file stream.h.
Referenced by _read(), _wait(), _write(), allocate(), close(), open(), ucommon::sstream::open(), release(), reset(), ucommon::sstream::sstream(), and tcpstream().
|
protected |
Definition at line 122 of file stream.h.
Referenced by _wait(), and tcpstream().