Ocean
Ocean::Network::Socket Class Reference

This class is the base class for all sockets. More...

Inheritance diagram for Ocean::Network::Socket:

Public Types

enum  SocketResult { SR_SUCCEEDED = 0 , SR_FAILED , SR_BUSY , SR_NOT_CONNECTED }
 Definition of individual result values. More...
 
typedef SOCKET SocketId
 Definition of a socket id. More...
 
typedef int SocketId
 Definition of a socket id. More...
 
typedef std::vector< uint8_t > Buffer
 Definition of a vector holding 8 bit values. More...
 

Public Member Functions

virtual ~Socket ()
 Destructs a socket object. More...
 
SocketId id () const
 Returns the socket id. More...
 
Address4 address () const
 Returns the own address of this socket. More...
 
Port port () const
 Returns the own port of this socket. More...
 
virtual bool setAddress (const Address4 &address)
 Sets the own address of this socket. More...
 
virtual bool setPort (const Port &port)
 Sets the own port of this socket. More...
 
 operator bool () const
 Returns whether this socket is valid. More...
 

Static Public Member Functions

static constexpr SocketId invalidSocketId ()
 Returns an invalid socket id. More...
 
static bool setBlockingMode (const SocketId socketId, const bool blocking)
 Sets the blocking mode of a socket. More...
 

Protected Member Functions

 Socket ()
 Creates a new socket object. More...
 
 Socket (const Socket &object)=delete
 Disabled copy constructor. More...
 
bool setBlockingMode (const bool blocking)
 Sets the blocking mode of this socket. More...
 
size_t maximalMessageSize (const size_t defaultSize=65536)
 Returns the maximal message size in bytes. More...
 
bool releaseSocket ()
 Releases the socket. More...
 
virtual bool onScheduler ()
 The scheduler event function. More...
 
Socketoperator= (const Socket &object)=delete
 Disabled copy operator. More...
 

Protected Attributes

SocketId socketId_ = invalidSocketId()
 Socket id. More...
 
Lock lock_
 Socket lock. More...
 
NetworkResource networkResource_
 The network resource object. More...
 

Friends

class SocketScheduler
 
class Resolver
 

Detailed Description

This class is the base class for all sockets.

Member Typedef Documentation

◆ Buffer

typedef std::vector<uint8_t> Ocean::Network::Socket::Buffer

Definition of a vector holding 8 bit values.

◆ SocketId [1/2]

Definition of a socket id.

◆ SocketId [2/2]

Definition of a socket id.

Member Enumeration Documentation

◆ SocketResult

Definition of individual result values.

Enumerator
SR_SUCCEEDED 

The function succeeded.

SR_FAILED 

The function failed.

SR_BUSY 

The function did not succeed as the resource was busy (not free, or would have blocked if configurated as blocking).

SR_NOT_CONNECTED 

The function could not succeed as the resource was not connected.

Constructor & Destructor Documentation

◆ ~Socket()

virtual Ocean::Network::Socket::~Socket ( )
virtual

Destructs a socket object.

◆ Socket() [1/2]

Ocean::Network::Socket::Socket ( )
protected

Creates a new socket object.

◆ Socket() [2/2]

Ocean::Network::Socket::Socket ( const Socket object)
protecteddelete

Disabled copy constructor.

Parameters
objectThe object which would be copied

Member Function Documentation

◆ address()

Address4 Ocean::Network::Socket::address ( ) const

Returns the own address of this socket.

If the systems supports more than one network address use this function to determine which address is used for this socket.

Returns
Own address

◆ id()

Socket::SocketId Ocean::Network::Socket::id ( ) const
inline

Returns the socket id.

Returns
Socket id

◆ invalidSocketId()

constexpr Socket::SocketId Ocean::Network::Socket::invalidSocketId ( )
staticconstexpr

Returns an invalid socket id.

Returns
Invalid socket id

◆ maximalMessageSize()

size_t Ocean::Network::Socket::maximalMessageSize ( const size_t  defaultSize = 65536)
protected

Returns the maximal message size in bytes.

Beware: Connection oriented socket have no message restrictions, in those cases the specified default value will be returned.

Parameters
defaultSizeDefault message size for connection oriented sockets
Returns
Maximal message size

◆ onScheduler()

virtual bool Ocean::Network::Socket::onScheduler ( )
protectedvirtual

The scheduler event function.

Returns
True, if the event function was busy; False, if the event function did nothing

Reimplemented in Ocean::Network::PackagedConnectionlessServer, Ocean::Network::ConnectionOrientedServer, Ocean::Network::ConnectionOrientedClient, and Ocean::Network::ConnectionlessServer.

◆ operator bool()

Ocean::Network::Socket::operator bool ( ) const
inlineexplicit

Returns whether this socket is valid.

Returns
True, if so

◆ operator=()

Socket& Ocean::Network::Socket::operator= ( const Socket object)
protecteddelete

Disabled copy operator.

Parameters
objectThe object which would be copied
Returns
Reference to this object

◆ port()

Port Ocean::Network::Socket::port ( ) const

Returns the own port of this socket.

Returns
Own port

◆ releaseSocket()

bool Ocean::Network::Socket::releaseSocket ( )
protected

Releases the socket.

Returns
True, if succeeded

◆ setAddress()

virtual bool Ocean::Network::Socket::setAddress ( const Address4 address)
virtual

Sets the own address of this socket.

If the systems supports more than one network address use this function to define which address to use for this socket.
However, usually is not necessary to define the local address.

Parameters
addressThe address to use for this socket
Returns
True, if succeeded

◆ setBlockingMode() [1/2]

bool Ocean::Network::Socket::setBlockingMode ( const bool  blocking)
protected

Sets the blocking mode of this socket.

Parameters
blockingTrue, if the socket will block
Returns
True, if succeeded

◆ setBlockingMode() [2/2]

static bool Ocean::Network::Socket::setBlockingMode ( const SocketId  socketId,
const bool  blocking 
)
static

Sets the blocking mode of a socket.

Parameters
socketIdThe id of the socket for which the mode will be set, must be valid
blockingTrue, if the socket will block
Returns
True, if succeeded

◆ setPort()

virtual bool Ocean::Network::Socket::setPort ( const Port port)
virtual

Sets the own port of this socket.

Parameters
portOwn port to set
Returns
True, if succeeded

Reimplemented in Ocean::Network::PackagedUDPServer.

Friends And Related Function Documentation

◆ Resolver

friend class Resolver
friend

◆ SocketScheduler

friend class SocketScheduler
friend

Field Documentation

◆ lock_

Lock Ocean::Network::Socket::lock_
mutableprotected

Socket lock.

◆ networkResource_

NetworkResource Ocean::Network::Socket::networkResource_
protected

The network resource object.

◆ socketId_

SocketId Ocean::Network::Socket::socketId_ = invalidSocketId()
protected

Socket id.


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