forb
Classes | Public Member Functions | Static Public Member Functions | List of all members
forb::streams::socket Class Reference

C++ wrapper of the Socket POSIX API, which uses IPv4 and blocking communication. More...

#include <socket.hpp>

Inheritance diagram for forb::streams::socket:
forb::streams::stream

Public Member Functions

 socket ()=default
 Default constructor, creates an empty socket, which cannot be used to exchange data.
 
 ~socket () override
 Virtual destructor that closes the socket (if open).
 
 socket (const socket &other)=delete
 This class does not support copy construction.
 
socketoperator= (const socket &other)=delete
 This class does not support copy assignment.
 
 socket (socket &&other) noexcept
 This class supports move construction. More...
 
socketoperator= (socket &&other) noexcept
 This class supports move assignment. More...
 
socket accept ()
 Performs the accept operation on the given server socket. More...
 
void send (const void *buffer, std::size_t size) override
 Blocking wrapper of the POSIX send function. More...
 
void recv (void *buffer, std::size_t size) override
 Blocking wrapper of the POSIX recv function. More...
 
void close () noexcept override
 Closes the socket, called by the virtual destructor.
 
type get_type () const override
 Returns the type of the stream.
 
bool require_marshal () const override
 Returns true if the execution platform requires marshalling before sending data on the socket, false otherwise. More...
 
- Public Member Functions inherited from forb::streams::stream
virtual ~stream () noexcept=default
 This class is virtual, so it requires a virtual destructor. More...
 

Static Public Member Functions

static socket make_server (int port, int listen_queue_size=10)
 Creates a new server socket. More...
 
static socket make_server (const std::string &address, int port, int listen_queue_size=10)
 Creates a new server socket. More...
 
static socket make_client (const std::string &address, int port)
 Creates a new client socket, connected to the specified remote host.
 

Additional Inherited Members

- Public Types inherited from forb::streams::stream
enum  type : call_id_t { SOCKET = 0, SHMEM = 1 << (std::numeric_limits<call_id_t>::digits - 1) }
 The type of the stream. More...
 
using size_t = std::size_t
 An unsigned size type.
 

Detailed Description

C++ wrapper of the Socket POSIX API, which uses IPv4 and blocking communication.

Constructor & Destructor Documentation

§ socket()

forb::streams::socket::socket ( socket &&  other)
noexcept

This class supports move construction.

The moved socket gets reset to the default values for each of its attributes.

Member Function Documentation

§ accept()

forb::streams::socket forb::streams::socket::accept ( )

Performs the accept operation on the given server socket.

Socket must be a server socket (i.e. a socket that executed a bind and a listen before).

§ make_server() [1/2]

static socket forb::streams::socket::make_server ( int  port,
int  listen_queue_size = 10 
)
inlinestatic

Creates a new server socket.

The new server will be binded to any address on the local machine. The listen_queue_size argument is optional and defaulted to 10.

§ make_server() [2/2]

static socket forb::streams::socket::make_server ( const std::string &  address,
int  port,
int  listen_queue_size = 10 
)
inlinestatic

Creates a new server socket.

The new server will be binded to the address specified as argument, or to any address on the local machine if an empty string is given as argument. The listen_queue_size argument is optional and defaulted to 10.

§ operator=()

forb::streams::socket & forb::streams::socket::operator= ( socket &&  other)
noexcept

This class supports move assignment.

The moved socket gets reset to the default values for each of its attributes.

§ recv()

void forb::streams::socket::recv ( void *  buffer,
std::size_t  size 
)
overridevirtual

Blocking wrapper of the POSIX recv function.

It repeats the underlying call until all data are received or an error occurs.

Implements forb::streams::stream.

§ require_marshal()

bool forb::streams::socket::require_marshal ( ) const
inlineoverridevirtual

Returns true if the execution platform requires marshalling before sending data on the socket, false otherwise.

Sending over a network requires marshalling (byteswapping) if the machine is not big endian.

Reimplemented from forb::streams::stream.

§ send()

void forb::streams::socket::send ( const void *  buffer,
std::size_t  size 
)
overridevirtual

Blocking wrapper of the POSIX send function.

It repeats the underlying call until all data are sent or an error occurs.

Implements forb::streams::stream.


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