The Micro C++ Library
micxx::StreamSocket Class Reference

A StreamSocket represents one endpoint of a bidirectional, reliable, in-order stream oriented connection as used with the Transmission Control Protocol (TCP). More...

#include <micxx.hxx>

Inherits micxx::Socket, and micxx::traits::BiDiConnection.

Inherited by micxx::ClientSocket.

List of all members.

Public Member Functions

 StreamSocket ()
 Create a new unbound, disconnected StreamSocket.
virtual void bind (unsigned short port)
 Bind this socket to the specified port on localhost.
virtual void close (ClosingMode closingMode=BiDirectional)
 Close this socket and release underlying system resources.
virtual bool getLinger () const
 The current value of the member l_onoff of the struct linger socket option SO_LINGER of level SOL_SOCKET.
virtual unsigned short getLingerTimeout () const
 The current value of the member l_linger of the struct linger socket option SO_LINGER of level SOL_SOCKET.
virtual std::string readLn ()
 Read a single text line separated by the next newline character '\n'.
virtual void readLn (std::string &line)
 Read a single text line separated by the next newline character '\n'.
virtual int recv (void *bytes, size_t size, bool blocking=true)
 Try to receive up to size number of bytes from this StreamSocket.
virtual int send (const void *bytes, size_t size, bool blocking=true)
 Try to send up to size number of bytes from this StreamSocket.
virtual void setLinger (bool value, unsigned short timeout)
 Set the current value of the members l_onoff and l_linger of the struct linger socket option SO_LINGER of level SOL_SOCKET.
virtual std::string toString () const
 Returns a printable representation.

Protected Member Functions

 StreamSocket (socket_t rawSocket, SocketAddress *socketAddress)
 Create a StreamSocket to an already connected rawSocket socket descriptor bound to the specified socketAddress.
virtual void createSocket (int addressFamily)
 Create the underlying socket descriptor for the specified addressFamily.

Detailed Description

A StreamSocket represents one endpoint of a bidirectional, reliable, in-order stream oriented connection as used with the Transmission Control Protocol (TCP).

Author:
Norbert Klose
Date:
February, 2007

Constructor & Destructor Documentation

micxx::StreamSocket::StreamSocket ( )

Create a new unbound, disconnected StreamSocket.

micxx::StreamSocket::StreamSocket ( socket_t  rawSocket,
SocketAddress socketAddress 
) [protected]

Create a StreamSocket to an already connected rawSocket socket descriptor bound to the specified socketAddress.

Parameters:
rawSocketthe socket descriptor
socketAddressthe socket address to be used internally. This socket takes ownership of the allocated SocketAdress and gets responsible for deleting it
See also:
ClientSocket::ClientSocket(socket_t, SocketAddress*)

Member Function Documentation

virtual void micxx::StreamSocket::bind ( unsigned short  port) [virtual]

Bind this socket to the specified port on localhost.

virtual void micxx::StreamSocket::close ( ClosingMode  closingMode = BiDirectional) [virtual]

Close this socket and release underlying system resources.

Reimplemented from micxx::Socket.

Reimplemented in micxx::SSLClientSocket.

virtual void micxx::StreamSocket::createSocket ( int  addressFamily) [protected, virtual]

Create the underlying socket descriptor for the specified addressFamily.

Parameters:
addressFamilyThe family of the stored SocketAddress.
See also:
SocketAddress::getFamily()

Reimplemented from micxx::Socket.

virtual bool micxx::StreamSocket::getLinger ( ) const [virtual]

The current value of the member l_onoff of the struct linger socket option SO_LINGER of level SOL_SOCKET.

See also:
getsockopt(socket_t, SOL_SOCKET, SO_LINGER, struct linger*, socklen_t*)
virtual unsigned short micxx::StreamSocket::getLingerTimeout ( ) const [virtual]

The current value of the member l_linger of the struct linger socket option SO_LINGER of level SOL_SOCKET.

See also:
getsockopt(socket_t, SOL_SOCKET, SO_LINGER, struct linger*, socklen_t*)
virtual std::string micxx::StreamSocket::readLn ( ) [virtual]

Read a single text line separated by the next newline character '\n'.

Returns:
The read text incl. the separating newline character.
virtual void micxx::StreamSocket::readLn ( std::string &  line) [virtual]

Read a single text line separated by the next newline character '\n'.

Parameters:
lineThe read line will appended to line.
virtual int micxx::StreamSocket::recv ( void *  bytes,
size_t  size,
bool  blocking = true 
) [virtual]

Try to receive up to size number of bytes from this StreamSocket.

Parameters:
bytesThe pointer to the receiving buffer
sizeThe number of bytes to be expected to be received
blockingIf blocking is true, then the call waits until all size bytes were received. Otherwise, it returns as soon as possible.
Returns:
The number of bytes received and written to bytes. If the connection has been closed, the return value is 0.

Reimplemented in micxx::SSLClientSocket.

virtual int micxx::StreamSocket::send ( const void *  bytes,
size_t  size,
bool  blocking = true 
) [virtual]

Try to send up to size number of bytes from this StreamSocket.

Parameters:
bytesThe pointer to the sending buffer
sizeThe number of bytes to be expected to be sent
blockingIf blocking is true, then the call waits until all size bytes were sent. Otherwise, it returns as soon as possible.
Returns:
The number of bytes sent. If the connection has been closed, the return value is 0.

Implements micxx::traits::Sender.

Reimplemented in micxx::SSLClientSocket.

virtual void micxx::StreamSocket::setLinger ( bool  value,
unsigned short  timeout 
) [virtual]

Set the current value of the members l_onoff and l_linger of the struct linger socket option SO_LINGER of level SOL_SOCKET.

Parameters:
valueThe value passed to the l_onoff member of struct linger
timeoutThe value passed to the l_linger member of struct linger
See also:
setsockopt(socket_t, SOL_SOCKET, SO_LINGER, const struct linger*, socklen_t)
virtual std::string micxx::StreamSocket::toString ( ) const [virtual]

Returns a printable representation.

Reimplemented from micxx::Socket.


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