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

A Socket class could be bound to a SocketAddress and provides the interface to generic BSD socket API compliant Socket properties. More...

#include <micxx.hxx>

Inherits micxx::Mutex, and micxx::traits::Connection.

Inherited by micxx::DatagramSocket, micxx::ServerSocket, and micxx::StreamSocket.

List of all members.

Public Member Functions

virtual ~Socket ()
 Close the socket and delete the internal stored SocketAddress.
virtual void bind (const SocketAddress &socketAddress)
 Bind this Socket to the specified SocketAddress socketAddress.
virtual void close (ClosingMode closingMode=BiDirectional)
 Close this socket and release underlying system resources.
virtual const SocketAddressgetAddress () const
 The stored SocketAddress.
virtual std::size_t getReceiveBufferSize () const
 The current value for socket option SO_RCVBUF of level SOL_SOCKET.
virtual bool getReuseAddress () const
 The current value for socket option SO_REUSEADDR of level SOL_SOCKET.
virtual std::size_t getSendBufferSize () const
 The current value for socket option SO_SNDBUF of level SOL_SOCKET.
virtual int getSocketType () const
 The type of this Socket.
virtual operator socket_t ()
 The underlying socket descriptior.
virtual void setReceiveBufferSize (std::size_t value)
 Set the current value for socket option SO_RCVBUF of level SOL_SOCKET.
virtual void setReuseAddress (bool value)
 Set the current value for socket option SO_REUSEADDR of level SOL_SOCKET.
virtual void setSendBufferSize (std::size_t value)
 Set the current value for socket option SO_SNDBUF of level SOL_SOCKET.
virtual std::string toString () const
 Returns a printable representation.

Static Public Member Functions

static int getLastSocketError ()
 Return the last system error that was set by a underlying socket API call.

Protected Member Functions

 Socket (int socketType)
 Create a socket of the specified type.
 Socket (int socketType, socket_t rawSocket, SocketAddress *socketAddress)
 Create a Socket 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.
virtual void setAddress (const SocketAddress *socketAddress)
 Set this Socket's SocketAddress to a copy of socketAddress.

Protected Attributes

socket_t socket
 The underlying socket descriptor.

Detailed Description

A Socket class could be bound to a SocketAddress and provides the interface to generic BSD socket API compliant Socket properties.

Author:
Norbert Klose
Date:
December, 2006

Constructor & Destructor Documentation

virtual micxx::Socket::~Socket ( ) [virtual]

Close the socket and delete the internal stored SocketAddress.

micxx::Socket::Socket ( int  socketType) [protected]

Create a socket of the specified type.

Parameters:
socketTypeEither SOCK_STREAM or SOCK_DGRAM.
micxx::Socket::Socket ( int  socketType,
socket_t  rawSocket,
SocketAddress socketAddress 
) [protected]

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

Parameters:
socketTypeThe type of the socket.
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:
StreamSocket::StreamSocket(socket_t, SocketAddress*)

Member Function Documentation

virtual void micxx::Socket::bind ( const SocketAddress socketAddress) [virtual]

Bind this Socket to the specified SocketAddress socketAddress.

Parameters:
socketAddressA copy of socketAddress is stored internally.

Reimplemented in micxx::ServerSocket.

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

Close this socket and release underlying system resources.

Implements micxx::traits::Connection.

Reimplemented in micxx::SSLClientSocket, and micxx::StreamSocket.

virtual void micxx::Socket::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 in micxx::DatagramSocket, micxx::MulticastSocket, and micxx::StreamSocket.

virtual const SocketAddress* micxx::Socket::getAddress ( ) const [virtual]

The stored SocketAddress.

Returns:
The stored SocketAddress or 0, if no SocketAddress has been set so far.
static int micxx::Socket::getLastSocketError ( ) [static]

Return the last system error that was set by a underlying socket API call.

Returns:
If compiled for Windows Socket API WSAGetLastError() is returned. Otheriwse it simply returns errno.
virtual std::size_t micxx::Socket::getReceiveBufferSize ( ) const [virtual]

The current value for socket option SO_RCVBUF of level SOL_SOCKET.

See also:
getsockopt(socket_t, SOL_SOCKET, SO_RCVBUF, void*, socklen_t*)
virtual bool micxx::Socket::getReuseAddress ( ) const [virtual]

The current value for socket option SO_REUSEADDR of level SOL_SOCKET.

See also:
getsockopt(socket_t, SOL_SOCKET, SO_REUSEADDR, void*, socklen_t*)
virtual std::size_t micxx::Socket::getSendBufferSize ( ) const [virtual]

The current value for socket option SO_SNDBUF of level SOL_SOCKET.

See also:
getsockopt(socket_t, SOL_SOCKET, SO_SNDBUF, void*, socklen_t*)
virtual int micxx::Socket::getSocketType ( ) const [virtual]

The type of this Socket.

Returns:
Either SOCK_STREAM or SOCK_DGRAM
virtual micxx::Socket::operator socket_t ( ) [virtual]

The underlying socket descriptior.

Returns:
The underlying socket descriptior or INVALID_SOCKET, if not valid.
virtual void micxx::Socket::setAddress ( const SocketAddress socketAddress) [protected, virtual]

Set this Socket's SocketAddress to a copy of socketAddress.

Parameters:
socketAddressthe new SocketAddress to be set. A copy of socketAddress will be set. If socketAddress is 0 and the stored SocketAddress is set already, only this SocketAddress is deleted and reset to 0.

If this Socket has already a SocketAddress set, this is deleted before.

See also:
SocketAddress::clone()
virtual void micxx::Socket::setReceiveBufferSize ( std::size_t  value) [virtual]

Set the current value for socket option SO_RCVBUF of level SOL_SOCKET.

See also:
setsockopt(socket_t, SOL_SOCKET, SO_RCVBUF, const void*, socklen_t)
virtual void micxx::Socket::setReuseAddress ( bool  value) [virtual]

Set the current value for socket option SO_REUSEADDR of level SOL_SOCKET.

See also:
setsockopt(socket_t, SOL_SOCKET, SO_REUSEADDR, const void*, socklen_t)
virtual void micxx::Socket::setSendBufferSize ( std::size_t  value) [virtual]

Set the current value for socket option SO_SNDBUF of level SOL_SOCKET.

See also:
setsockopt(socket_t, SOL_SOCKET, SO_SNDBUF, const void*, socklen_t)
virtual std::string micxx::Socket::toString ( ) const [virtual]

Returns a printable representation.

Reimplemented from micxx::Mutex.

Reimplemented in micxx::ServerSocket, and micxx::StreamSocket.


Member Data Documentation

The underlying socket descriptor.


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