NetCpp  v0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
AbstractSystemSocket Class Reference

Virtual class for platform-dependent code. More...

#include <abstract_system_socket.hpp>

Inheritance diagram for AbstractSystemSocket:
Inheritance graph

Public Member Functions

virtual int read (void *buf, size_t size)=0
 Method to read data from the socket.
virtual int write (const void *buf, size_t size)=0
 Method to write data to the socket.
virtual bool close ()=0
 Method to close the socket.
virtual void accept (AbstractSystemSocket *sock)=0
 Method to accept a connection on a socket.
virtual void connect (const Address &addr)=0
 Method to connect the socket to an address.
virtual void bind (const Address &addr)=0
 Method to bind the socket to an address.
virtual void listen (int max_pending_connections)=0
 Method to set the maximum number of pending connections.
protocol getProtocol () const
 Method to get the socket protocol.

Protected Member Functions

 AbstractSystemSocket (const protocol &prot)
 Constructor.

Protected Attributes

protocol protocol_
 Protocol used by the socket.

Detailed Description

Virtual class for platform-dependent code.

This is the virtual class which every platform-dependent implementation must inherit from. The class offers a set of primitives which must be implemented by the concrete derived classes.

Definition at line 47 of file abstract_system_socket.hpp.

Constructor & Destructor Documentation

AbstractSystemSocket ( const protocol prot)
inlineprotected

Constructor.

The constructor is protected because only derived classes can use it.

Parameters
protProtocol used by the socket

Definition at line 130 of file abstract_system_socket.hpp.

:
protocol_{prot}{};

Member Function Documentation

virtual void accept ( AbstractSystemSocket sock)
pure virtual

Method to accept a connection on a socket.

Parameters
sockPointer to the socket on which the new connection must be accepted.
Exceptions
runtime_errorin case of error

Implemented in PosixSocket.

virtual void bind ( const Address addr)
pure virtual

Method to bind the socket to an address.

Parameters
addrAddress which the socket must be bound to
Exceptions
runtime_errorin case of error

Implemented in PosixSocket.

virtual bool close ( )
pure virtual

Method to close the socket.

Note: currently there is no mechanism to re-open a closed socket.

Returns
true in case of success; false otherwise

Implemented in PosixSocket.

virtual void connect ( const Address addr)
pure virtual

Method to connect the socket to an address.

Parameters
addrAddress which the socket must be connected to
Exceptions
runtime_errorin case of error

Implemented in PosixSocket.

protocol getProtocol ( ) const
inline

Method to get the socket protocol.

This method returns the protocol, which has been set at socket creation (and cannot be changed).

Returns
Protocol used by the socket

Definition at line 118 of file abstract_system_socket.hpp.

{
return protocol_;
}

Here is the caller graph for this function:

virtual void listen ( int  max_pending_connections)
pure virtual

Method to set the maximum number of pending connections.

This method allows to set the maximum number of pending connections for stream (e.g., TCP) communications.

Parameters
max_pending_connectionsMaximum number of pending connections
Exceptions
runtime_errorin case of error or non-streamed communication

Implemented in PosixSocket.

virtual int read ( void *  buf,
size_t  size 
)
pure virtual

Method to read data from the socket.

The buffer is filled with the read data.

Parameters
pbuf Pointer to the memory address containing data
sizeNumber of bytes that must be read
Returns
the number of bytes actually read; < 0 in case of error

Implemented in PosixSocket.

virtual int write ( const void *  buf,
size_t  size 
)
pure virtual

Method to write data to the socket.

Parameters
pbuf Pointer to the memory address containing data
sizeNumber of bytes that must be written
Returns
the number of bytes actually written; < 0 in case of error

Implemented in PosixSocket.

Member Data Documentation

protocol protocol_
protected

Protocol used by the socket.

This protocol is set during socket creation and cannot be changed.

Definition at line 131 of file abstract_system_socket.hpp.


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