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..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

ucommon::tcpstream Class Reference

#include <stream.h>

Inheritance diagram for ucommon::tcpstream:
[legend]
Collaboration diagram for ucommon::tcpstream:
[legend]

Public Member Functions

 tcpstream (const tcpstream &copy)
 
 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)
 
- Public Member Functions inherited from ucommon::StreamBuffer
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
 
- Protected Member Functions inherited from ucommon::StreamBuffer
 StreamBuffer ()
 
int uflow () __OVERRIDE
 
void release (void)
 
void allocate (size_t size)
 

Protected Attributes

socket_t so
 
timeout_t timeout
 
- Protected Attributes inherited from ucommon::StreamBuffer
size_t bufsize
 
char * gbuf
 
char * pbuf
 

Private Member Functions

__LOCAL void allocate (unsigned size)
 
__LOCAL void reset (void)
 

Detailed Description

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.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 114 of file stream.h.

Constructor & Destructor Documentation

◆ tcpstream() [1/4]

ucommon::tcpstream::tcpstream ( const tcpstream copy)

Copy constructor...

Parameters
copyfor object.

Definition at line 126 of file stream.cpp.

References ucommon::copy(), ucommon::Socket::create(), ucommon::Socket::family(), so, and timeout.

◆ tcpstream() [2/4]

ucommon::tcpstream::tcpstream ( const TCPServer server,
unsigned  segsize = 536,
timeout_t  timeout = 0 
)

Create a stream from an existing tcp listener.

Parameters
serverto accept connection from.
segsizefor tcp segments and buffering.
timeoutfor socket i/o operations.

Definition at line 148 of file stream.cpp.

References ucommon::ListenSocket::accept(), allocate(), ucommon::clear(), INVALID_SOCKET, so, and timeout.

◆ tcpstream() [3/4]

ucommon::tcpstream::tcpstream ( int  family = PF_INET,
timeout_t  timeout = 0 
)

Create an unconnected tcp stream object that is idle until opened.

Parameters
familyof protocol to create.
timeoutfor socket i/o operations.

Definition at line 133 of file stream.cpp.

References ucommon::Socket::create(), so, and timeout.

◆ tcpstream() [4/4]

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.

Parameters
addressof service to connect to.
segsizefor tcp segments and buffering.
timeoutfor socket i/o operations.

Definition at line 140 of file stream.cpp.

References ucommon::Socket::create(), ucommon::Socket::address::family(), open(), so, and timeout.

◆ ~tcpstream()

ucommon::tcpstream::~tcpstream ( )
virtual

Destroy a tcp stream.

Definition at line 160 of file stream.cpp.

References release().

Member Function Documentation

◆ _read()

ssize_t ucommon::tcpstream::_read ( char *  buffer,
size_t  size 
)
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().

◆ _wait()

bool ucommon::tcpstream::_wait ( void  )
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().

◆ _write()

ssize_t ucommon::tcpstream::_write ( const char *  buffer,
size_t  size 
)
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().

◆ allocate()

void ucommon::tcpstream::allocate ( unsigned  size)
private

◆ close()

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().

◆ getsocket()

socket_t ucommon::tcpstream::getsocket ( void  ) const
inlineprotected

Definition at line 151 of file stream.h.

◆ open() [1/2]

void ucommon::tcpstream::open ( const char *  host,
const char *  service,
unsigned  segment = 536 
)

Open a stream connectoion to a host and service.

Parameters
hostto connect to.
serviceto connect to by name or number as string.
segmentbuffering 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.

◆ open() [2/2]

void ucommon::tcpstream::open ( Socket::address address,
unsigned  segment = 536 
)

Open a stream connection to a tcp service.

Parameters
addressof service to access.
segmentbuffering 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().

◆ operator bool()

ucommon::tcpstream::operator bool ( ) const
inline

See if stream connection is active.

Returns
true if stream is active.

Definition at line 196 of file stream.h.

References INVALID_SOCKET.

◆ operator!()

bool ucommon::tcpstream::operator! ( void  ) const
inline

See if stream is disconnected.

Returns
true if stream disconnected.

Definition at line 204 of file stream.h.

References INVALID_SOCKET.

◆ overflow()

int ucommon::tcpstream::overflow ( int  ch)
protected

This streambuf method is used to write the output buffer through the established tcp connection.

Parameters
chchar to push through.
Returns
char pushed through.

Definition at line 240 of file stream.cpp.

References _write(), ucommon::StreamBuffer::bufsize, ch, EOF, IS_EOF, ucommon::StreamBuffer::pbuf, PUT, and reset().

◆ release()

void ucommon::tcpstream::release ( void  )
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().

◆ reset()

void ucommon::tcpstream::reset ( void  )
private

◆ underflow()

int ucommon::tcpstream::underflow ( void  )
protected

This streambuf method is used to load the input buffer through the established tcp socket connection.

Returns
char from get buffer, EOF if not connected.

Definition at line 193 of file stream.cpp.

References _read(), _wait(), ucommon::StreamBuffer::bufsize, ch, ucommon::clear(), EOF, ucommon::StreamBuffer::gbuf, GET, and reset().

Member Data Documentation

◆ so

socket_t ucommon::tcpstream::so
protected

◆ timeout

timeout_t ucommon::tcpstream::timeout
protected

Definition at line 122 of file stream.h.

Referenced by _wait(), and tcpstream().


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