join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::BasicSocket< Protocol > Class Template Reference

basic socket class. More...

#include <socket.hpp>

Inheritance diagram for join::BasicSocket< Protocol >:

Public Types

enum  Mode { Blocking , NonBlocking }
 socket modes. More...
 
enum  State {
  Connecting , Connected , Disconnecting , Disconnected ,
  Closed
}
 socket states. More...
 
using Ptr = std::unique_ptr<BasicSocket<Protocol>>
 
using Endpoint = typename Protocol::Endpoint
 
using TimePoint = std::chrono::steady_clock::time_point
 

Public Member Functions

 BasicSocket () noexcept
 default constructor.
 
 BasicSocket (Mode mode) noexcept
 create socket instance specifying the mode.
 
 BasicSocket (const BasicSocket &other)=delete
 copy constructor.
 
BasicSocketoperator= (const BasicSocket &other)=delete
 copy assignment operator.
 
 BasicSocket (BasicSocket &&other) noexcept
 move constructor.
 
BasicSocketoperator= (BasicSocket &&other) noexcept
 move assignment operator.
 
virtual ~BasicSocket ()
 destroy the socket instance.
 
virtual int open (const Protocol &protocol=Protocol()) noexcept
 open socket using the given protocol.
 
virtual void close () noexcept
 close the socket.
 
virtual int bind (const Endpoint &endpoint) noexcept
 assigns the specified endpoint to the socket.
 
bool waitReadyRead () const noexcept
 block until new data is available for reading.
 
bool waitReadyRead (std::chrono::nanoseconds timeout) const noexcept
 block until new data is available for reading, giving up after the given duration.
 
bool waitReadyRead (TimePoint deadline) const noexcept
 block until new data is available for reading, giving up at the given time point.
 
bool waitReadyWrite () const noexcept
 block until at least one byte can be written.
 
bool waitReadyWrite (std::chrono::nanoseconds timeout) const noexcept
 block until at least one byte can be written, giving up after the given duration.
 
bool waitReadyWrite (TimePoint deadline) const noexcept
 block until at least one byte can be written, giving up at the given time point.
 
void setMode (Mode mode) noexcept
 set the socket to the non-blocking or blocking mode.
 
Endpoint localEndpoint () const noexcept
 determine the local endpoint associated with this socket.
 
bool opened () const noexcept
 check if the socket is opened.
 
int family () const noexcept
 get socket address family.
 
int type () const noexcept
 get the protocol communication semantic.
 
int protocol () const noexcept
 get socket protocol.
 
Mode mode () const noexcept
 get the blocking mode of the socket.
 
int handle () const noexcept
 get socket native handle.
 
int wait (bool wantRead, bool wantWrite) const noexcept
 wait for the socket handle to become ready.
 
int waitFor (bool wantRead, bool wantWrite, std::chrono::nanoseconds timeout) const noexcept
 wait for the socket handle to become ready, giving up after the given duration.
 
int waitUntil (bool wantRead, bool wantWrite, TimePoint deadline) const noexcept
 wait for the socket handle to become ready, giving up at the given time point.
 

Protected Attributes

State _state = State::Closed
 socket state.
 
Mode _mode = Mode::NonBlocking
 socket mode.
 
int _handle = -1
 socket handle.
 
Protocol _protocol
 protocol.
 

Friends

template<class P , class E , size_t N>
class BasicAsyncRawSocket
 friendship with basic asynchronous raw socket
 

Detailed Description

template<class Protocol>
class join::BasicSocket< Protocol >

basic socket class.

Member Typedef Documentation

◆ Endpoint

template<class Protocol >
using join::BasicSocket< Protocol >::Endpoint = typename Protocol::Endpoint

◆ Ptr

template<class Protocol >
using join::BasicSocket< Protocol >::Ptr = std::unique_ptr<BasicSocket<Protocol>>

◆ TimePoint

template<class Protocol >
using join::BasicSocket< Protocol >::TimePoint = std::chrono::steady_clock::time_point

Member Enumeration Documentation

◆ Mode

template<class Protocol >
enum join::BasicSocket::Mode

socket modes.

Enumerator
Blocking 

the socket will block

NonBlocking 

the socket will not block

◆ State

template<class Protocol >
enum join::BasicSocket::State

socket states.

Enumerator
Connecting 

socket is connecting.

Connected 

socket is connected.

Disconnecting 

socket is disconnecting.

Disconnected 

socket is disconnected.

Closed 

socket is closed.

Constructor & Destructor Documentation

◆ BasicSocket() [1/4]

template<class Protocol >
join::BasicSocket< Protocol >::BasicSocket ( )
inlinenoexcept

default constructor.

◆ BasicSocket() [2/4]

template<class Protocol >
join::BasicSocket< Protocol >::BasicSocket ( Mode mode)
inlineexplicitnoexcept

create socket instance specifying the mode.

Parameters
modeblocking mode.

◆ BasicSocket() [3/4]

template<class Protocol >
join::BasicSocket< Protocol >::BasicSocket ( const BasicSocket< Protocol > & other)
delete

copy constructor.

Parameters
otherother object to copy.

◆ BasicSocket() [4/4]

template<class Protocol >
join::BasicSocket< Protocol >::BasicSocket ( BasicSocket< Protocol > && other)
inlinenoexcept

move constructor.

Parameters
otherother object to move.

◆ ~BasicSocket()

template<class Protocol >
virtual join::BasicSocket< Protocol >::~BasicSocket ( )
inlinevirtual

destroy the socket instance.

Member Function Documentation

◆ bind()

template<class Protocol >
virtual int join::BasicSocket< Protocol >::bind ( const Endpoint & endpoint)
inlinevirtualnoexcept

assigns the specified endpoint to the socket.

Parameters
endpointendpoint to assign to the socket.
Returns
0 on success, -1 on failure.

Reimplemented in join::BasicRawSocket< Protocol >, join::BasicRawSocket< Netlink >, and join::BasicRawSocket< Raw >.

◆ close()

template<class Protocol >
virtual void join::BasicSocket< Protocol >::close ( )
inlinevirtualnoexcept

◆ family()

template<class Protocol >
int join::BasicSocket< Protocol >::family ( ) const
inlinenoexcept

get socket address family.

Returns
socket address family.

◆ handle()

template<class Protocol >
int join::BasicSocket< Protocol >::handle ( ) const
inlinenoexcept

get socket native handle.

Returns
socket native handle.

◆ localEndpoint()

template<class Protocol >
Endpoint join::BasicSocket< Protocol >::localEndpoint ( ) const
inlinenoexcept

determine the local endpoint associated with this socket.

Returns
local endpoint.

◆ mode()

template<class Protocol >
Mode join::BasicSocket< Protocol >::mode ( ) const
inlinenoexcept

get the blocking mode of the socket.

Returns
the blocking mode of the socket.

◆ open()

template<class Protocol >
virtual int join::BasicSocket< Protocol >::open ( const Protocol & protocol = Protocol ())
inlinevirtualnoexcept

open socket using the given protocol.

Parameters
protocolprotocol to use.
Returns
0 on success, -1 on failure.

Reimplemented in join::BasicDatagramSocket< Protocol >, and join::BasicDatagramSocket< Netlink >.

◆ opened()

template<class Protocol >
bool join::BasicSocket< Protocol >::opened ( ) const
inlinenoexcept

check if the socket is opened.

Returns
true if opened, false otherwise.

◆ operator=() [1/2]

template<class Protocol >
BasicSocket & join::BasicSocket< Protocol >::operator= ( BasicSocket< Protocol > && other)
inlinenoexcept

move assignment operator.

Parameters
otherother object to assign.
Returns
current object.

◆ operator=() [2/2]

template<class Protocol >
BasicSocket & join::BasicSocket< Protocol >::operator= ( const BasicSocket< Protocol > & other)
delete

copy assignment operator.

Parameters
otherother object to assign.
Returns
current object.

◆ protocol()

template<class Protocol >
int join::BasicSocket< Protocol >::protocol ( ) const
inlinenoexcept

get socket protocol.

Returns
socket protocol.

◆ setMode()

template<class Protocol >
void join::BasicSocket< Protocol >::setMode ( Mode mode)
inlinenoexcept

set the socket to the non-blocking or blocking mode.

Parameters
modeblocking mode.

◆ type()

template<class Protocol >
int join::BasicSocket< Protocol >::type ( ) const
inlinenoexcept

get the protocol communication semantic.

Returns
the protocol communication semantic.

◆ wait()

template<class Protocol >
int join::BasicSocket< Protocol >::wait ( bool wantRead,
bool wantWrite ) const
inlinenoexcept

wait for the socket handle to become ready.

Parameters
wantReadset to true if want read
wantWriteset to true if want write.
Returns
0 on success, -1 on failure.

◆ waitFor()

template<class Protocol >
int join::BasicSocket< Protocol >::waitFor ( bool wantRead,
bool wantWrite,
std::chrono::nanoseconds timeout ) const
inlinenoexcept

wait for the socket handle to become ready, giving up after the given duration.

Parameters
wantReadset to true if want read
wantWriteset to true if want write.
timeoutmaximum time to wait.
Returns
0 on success, -1 on failure.

◆ waitReadyRead() [1/3]

template<class Protocol >
bool join::BasicSocket< Protocol >::waitReadyRead ( ) const
inlinenoexcept

block until new data is available for reading.

Returns
true if there is new data available for reading, false otherwise.

◆ waitReadyRead() [2/3]

template<class Protocol >
bool join::BasicSocket< Protocol >::waitReadyRead ( std::chrono::nanoseconds timeout) const
inlinenoexcept

block until new data is available for reading, giving up after the given duration.

Parameters
timeoutmaximum time to wait.
Returns
true if there is new data available for reading, false otherwise.

◆ waitReadyRead() [3/3]

template<class Protocol >
bool join::BasicSocket< Protocol >::waitReadyRead ( TimePoint deadline) const
inlinenoexcept

block until new data is available for reading, giving up at the given time point.

Parameters
deadlinetime point at which to give up, max to wait indefinitely.
Returns
true if there is new data available for reading, false otherwise.

◆ waitReadyWrite() [1/3]

template<class Protocol >
bool join::BasicSocket< Protocol >::waitReadyWrite ( ) const
inlinenoexcept

block until at least one byte can be written.

Returns
true if data can be written, false otherwise.

◆ waitReadyWrite() [2/3]

template<class Protocol >
bool join::BasicSocket< Protocol >::waitReadyWrite ( std::chrono::nanoseconds timeout) const
inlinenoexcept

block until at least one byte can be written, giving up after the given duration.

Parameters
timeoutmaximum time to wait.
Returns
true if data can be written, false otherwise.

◆ waitReadyWrite() [3/3]

template<class Protocol >
bool join::BasicSocket< Protocol >::waitReadyWrite ( TimePoint deadline) const
inlinenoexcept

block until at least one byte can be written, giving up at the given time point.

Parameters
deadlinetime point at which to give up, max to wait indefinitely.
Returns
true if data can be written, false otherwise.

◆ waitUntil()

template<class Protocol >
int join::BasicSocket< Protocol >::waitUntil ( bool wantRead,
bool wantWrite,
TimePoint deadline ) const
inlinenoexcept

wait for the socket handle to become ready, giving up at the given time point.

Parameters
wantReadset to true if want read
wantWriteset to true if want write.
deadlinetime point at which to give up, max to wait indefinitely.
Returns
0 on success, -1 on failure.

Friends And Related Symbol Documentation

◆ BasicAsyncRawSocket

template<class Protocol >
template<class P , class E , size_t N>
friend class BasicAsyncRawSocket
friend

friendship with basic asynchronous raw socket

Member Data Documentation

◆ _handle

template<class Protocol >
int join::BasicSocket< Protocol >::_handle = -1
protected

socket handle.

◆ _mode

template<class Protocol >
Mode join::BasicSocket< Protocol >::_mode = Mode::NonBlocking
protected

socket mode.

◆ _protocol

template<class Protocol >
Protocol join::BasicSocket< Protocol >::_protocol
protected

protocol.

◆ _state

template<class Protocol >
State join::BasicSocket< Protocol >::_state = State::Closed
protected

socket state.


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