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

basic raw socket class. More...

#include <raw_socket.hpp>

Inheritance diagram for join::BasicRawSocket< Protocol >:
Collaboration diagram for join::BasicRawSocket< Protocol >:

Public Types

enum  Option {
  NoDelay , KeepAlive , KeepIdle , KeepIntvl ,
  KeepCount , SndBuffer , RcvBuffer , TimeStamp ,
  ReuseAddr , ReusePort , Broadcast , Ttl ,
  MulticastLoop , MulticastTtl , PathMtuDiscover , RcvError ,
  AuxData
}
 socket options. More...
 
using Ptr = std::unique_ptr<BasicRawSocket<Protocol>>
 
using Mode = typename BasicSocket<Protocol>::Mode
 
using State = typename BasicSocket<Protocol>::State
 
using Endpoint = typename Protocol::Endpoint
 
- Public Types inherited from join::BasicSocket< Protocol >
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

 BasicRawSocket () noexcept
 default constructor.
 
 BasicRawSocket (Mode mode) noexcept
 create socket instance specifying the mode.
 
 BasicRawSocket (const BasicRawSocket &other)=delete
 copy constructor.
 
BasicRawSocketoperator= (const BasicRawSocket &other)=delete
 copy assignment operator.
 
 BasicRawSocket (BasicRawSocket &&other) noexcept=default
 move constructor.
 
BasicRawSocketoperator= (BasicRawSocket &&other) noexcept=default
 move assignment operator.
 
virtual ~BasicRawSocket ()=default
 destroy the socket instance.
 
int bind (const Endpoint &endpoint) noexcept override
 assigns the specified endpoint to the socket.
 
int bindToDevice (const std::string &device) noexcept
 assigns the specified device to the socket.
 
ssize_t canRead () const noexcept
 get the number of readable bytes.
 
ssize_t read (char *data, size_t maxSize) noexcept
 read data.
 
ssize_t write (const char *data, size_t maxSize) noexcept
 write data.
 
virtual int setOption (Option option, int value) noexcept
 set the given option to the given value.
 
- Public Member Functions inherited from join::BasicSocket< Protocol >
 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.
 
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.
 

Additional Inherited Members

- Protected Attributes inherited from join::BasicSocket< Protocol >
State _state = State::Closed
 socket state.
 
Mode _mode = Mode::NonBlocking
 socket mode.
 
int _handle = -1
 socket handle.
 
Protocol _protocol
 protocol.
 

Detailed Description

template<class Protocol>
class join::BasicRawSocket< Protocol >

basic raw socket class.

Member Typedef Documentation

◆ Endpoint

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

◆ Mode

template<class Protocol >
using join::BasicRawSocket< Protocol >::Mode = typename BasicSocket<Protocol>::Mode

◆ Ptr

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

◆ State

template<class Protocol >
using join::BasicRawSocket< Protocol >::State = typename BasicSocket<Protocol>::State

Member Enumeration Documentation

◆ Option

template<class Protocol >
enum join::BasicRawSocket::Option

socket options.

Enumerator
NoDelay 

set the TCP_NODELAY option to disable/enable the nagle's algorithm.

KeepAlive 

set the SO_KEEPALIVE option.

KeepIdle 

set the keepalive idle timeout option.

KeepIntvl 

set the keepalive probe interval option.

KeepCount 

set the keepalive probe count option.

SndBuffer 

set the socket send buffer size at the OS level.

RcvBuffer 

set the socket receive buffer size at the OS level.

TimeStamp 

enable or disable the receiving of the SO_TIMESTAMP control message.

ReuseAddr 

allow reuse of local addresses.

ReusePort 

permits multiple sockets to be bound to an identical socket address.

Broadcast 

allow datagram sockets to send packets to a broadcast address.

Ttl 

set the time-to-live value of outgoing packets.

MulticastLoop 

determines whether multicast packets should be looped back to the local sockets.

MulticastTtl 

set the time-to-live value of outgoing multicast packets.

PathMtuDiscover 

set the Path MTU Discovery setting for a socket.

RcvError 

enable extended reliable error message passing.

AuxData 

enable extended metadata message passing.

Constructor & Destructor Documentation

◆ BasicRawSocket() [1/4]

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

default constructor.

◆ BasicRawSocket() [2/4]

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

create socket instance specifying the mode.

Parameters
modeblocking mode.

◆ BasicRawSocket() [3/4]

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

copy constructor.

Parameters
otherother object to copy.

◆ BasicRawSocket() [4/4]

template<class Protocol >
join::BasicRawSocket< Protocol >::BasicRawSocket ( BasicRawSocket< Protocol > && other)
defaultnoexcept

move constructor.

Parameters
otherother object to move.

◆ ~BasicRawSocket()

template<class Protocol >
virtual join::BasicRawSocket< Protocol >::~BasicRawSocket ( )
virtualdefault

destroy the socket instance.

Member Function Documentation

◆ bind()

template<class Protocol >
int join::BasicRawSocket< Protocol >::bind ( const Endpoint & endpoint)
inlineoverridevirtualnoexcept

assigns the specified endpoint to the socket.

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

Reimplemented from join::BasicSocket< Protocol >.

◆ bindToDevice()

template<class Protocol >
int join::BasicRawSocket< Protocol >::bindToDevice ( const std::string & device)
inlinenoexcept

assigns the specified device to the socket.

Parameters
devicedevice name.
Returns
0 on success, -1 on failure.

◆ canRead()

template<class Protocol >
ssize_t join::BasicRawSocket< Protocol >::canRead ( ) const
inlinenoexcept

get the number of readable bytes.

Returns
the number of readable bytes, -1 on failure.

◆ operator=() [1/2]

template<class Protocol >
BasicRawSocket & join::BasicRawSocket< Protocol >::operator= ( BasicRawSocket< Protocol > && other)
defaultnoexcept

move assignment operator.

Parameters
otherother object to assign.
Returns
current object.

◆ operator=() [2/2]

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

copy assignment operator.

Parameters
otherother object to assign.
Returns
current object.

◆ read()

template<class Protocol >
ssize_t join::BasicRawSocket< Protocol >::read ( char * data,
size_t maxSize )
inlinenoexcept

read data.

Parameters
databuffer used to store the data received.
maxSizemaximum number of bytes to read.
Returns
the number of bytes received, -1 on failure.

◆ setOption()

template<class Protocol >
virtual int join::BasicRawSocket< Protocol >::setOption ( Option option,
int value )
inlinevirtualnoexcept

set the given option to the given value.

Parameters
optionsocket option.
valueoption value.
Returns
0 on success, -1 on failure.

Reimplemented in join::BasicStreamSocket< Protocol >.

◆ write()

template<class Protocol >
ssize_t join::BasicRawSocket< Protocol >::write ( const char * data,
size_t maxSize )
inlinenoexcept

write data.

Parameters
datadata buffer to send.
maxSizemaximum number of bytes to write.
Returns
the number of bytes written, -1 on failure.

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