join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount > Class Template Reference

asynchronous datagram socket class. More...

#include <async_datagram_socket.hpp>

Inheritance diagram for join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >:
Collaboration diagram for join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >:

Public Types

using Socket = typename Protocol::Socket
 
using Endpoint = typename Protocol::Endpoint
 
using AsyncRead = BasicAsyncRead<Protocol, Proactor>
 
using AsyncWrite = BasicAsyncWrite<Protocol, Proactor>
 
using ReadFromHandler = typename AsyncRead::ReadFrom
 
using WriteHandler = typename AsyncWrite::Write
 
- Public Types inherited from join::BasicAsyncRawSocket< Protocol, BasicProactor, 16 >
using Socket
 
using Endpoint
 
using Option
 
using AsyncRead
 
using AsyncWrite
 
using ReadHandler
 
using ReadFromHandler
 
using ConnectHandler
 
using WriteHandler
 
- Public Types inherited from join::BasicAsyncSocket< Protocol, BasicProactor, OpCount >
using Socket
 
using Endpoint
 
using AsyncWait
 
using WaitHandler
 
using OpArena
 

Public Member Functions

 BasicAsyncDatagramSocket (Proactor &proactor=ProactorThread::proactor())
 create the socket instance.
 
 BasicAsyncDatagramSocket (int ttl, Proactor &proactor=ProactorThread::proactor())
 create the socket instance specifying the time to live.
 
 BasicAsyncDatagramSocket (Socket &&sock, Proactor &proactor=ProactorThread::proactor())
 create the socket instance adopting an already opened socket.
 
 BasicAsyncDatagramSocket (const BasicAsyncDatagramSocket &other)=delete
 copy constructor.
 
BasicAsyncDatagramSocketoperator= (const BasicAsyncDatagramSocket &other)=delete
 copy assignment operator.
 
 BasicAsyncDatagramSocket (BasicAsyncDatagramSocket &&other) noexcept=default
 move constructor.
 
BasicAsyncDatagramSocketoperator= (BasicAsyncDatagramSocket &&other) noexcept=default
 move assignment operator.
 
int connect (const Endpoint &endpoint) noexcept
 assign the default remote endpoint for this socket.
 
int disconnect () noexcept
 remove the default remote endpoint.
 
ssize_t asyncReadFrom (char *data, size_t maxSize, Endpoint &endpoint, ReadFromHandler handler, bool flush=true, bool link=false) noexcept
 start an asynchronous read, reporting the endpoint the data are coming from.
 
ssize_t asyncReadFromMulti (uint16_t group, ReadFromHandler handler, bool flush=true) noexcept
 start an asynchronous multishot read, reporting the endpoint the data are coming from.
 
ssize_t asyncWriteTo (const char *data, size_t size, Endpoint &endpoint, WriteHandler handler, bool flush=true, bool link=false) noexcept
 start an asynchronous write to the given endpoint.
 
const EndpointremoteEndpoint () const noexcept
 determine the remote endpoint associated with this socket.
 
bool connected () const noexcept
 check if the socket is connected.
 
int mtu () const noexcept
 get socket mtu.
 
int ttl () const noexcept
 returns the Time-To-Live value.
 
- Public Member Functions inherited from join::BasicAsyncRawSocket< Protocol, BasicProactor, 16 >
 BasicAsyncRawSocket (BasicProactor &proactor=ProactorThread::proactor())
 create the socket instance.
 
 BasicAsyncRawSocket (Socket &&sock, BasicProactor &proactor=ProactorThread::proactor())
 create the socket instance adopting an already opened socket.
 
 BasicAsyncRawSocket (const BasicAsyncRawSocket &other)=delete
 copy constructor.
 
 BasicAsyncRawSocket (BasicAsyncRawSocket &&other) noexcept
 move constructor.
 
BasicAsyncRawSocketoperator= (const BasicAsyncRawSocket &other)=delete
 copy assignment operator.
 
BasicAsyncRawSocketoperator= (BasicAsyncRawSocket &&other) noexcept
 move assignment operator.
 
 ~BasicAsyncRawSocket ()
 destroy the socket instance.
 
int bind (const Endpoint &endpoint) noexcept
 assign the specified endpoint to the socket.
 
int bindToDevice (const std::string &device) noexcept
 assign the specified device to the socket.
 
int canRead () const noexcept
 get the number of readable bytes.
 
ssize_t asyncRead (char *data, size_t maxSize, ReadHandler handler, bool flush=true, bool link=false) noexcept
 start an asynchronous read.
 
ssize_t asyncReadMulti (uint16_t group, ReadHandler handler, bool flush=true) noexcept
 start an asynchronous multishot read, staying armed until cancelled or failed.
 
ssize_t asyncWrite (const char *data, size_t size, WriteHandler handler, bool flush=true, bool link=false) noexcept
 start an asynchronous write.
 
int cancelConnect () noexcept
 cancel the connect operation in flight, if any.
 
int setOption (Option option, int value) noexcept
 set the given option to the given value.
 
- Public Member Functions inherited from join::BasicAsyncSocket< Protocol, BasicProactor, OpCount >
BasicAsyncSocketoperator= (const BasicAsyncSocket &other)=delete
 copy assignment operator.
 
BasicAsyncSocketoperator= (BasicAsyncSocket &&other) noexcept
 move assignment operator.
 
 ~BasicAsyncSocket ()
 destroy the socket instance.
 
int open (const Protocol &protocol=Protocol()) noexcept
 open socket using the given protocol.
 
void close () noexcept
 close the socket, cancelling the operations in flight.
 
int registerBufferRing (uint16_t group, LocalMem::Allocator< Count, Size > &arena)
 register a provided buffer ring on the proactor driving this socket.
 
int unregisterBufferRing (uint16_t group)
 unregister a provided buffer ring from the proactor driving this socket.
 
ssize_t asyncWait (bool wantRead, bool wantWrite, WaitHandler handler, bool flush=true) noexcept
 start an asynchronous wait for the socket to become ready in one direction.
 
ssize_t asyncWaitMulti (bool wantRead, bool wantWrite, WaitHandler handler, bool flush=true) noexcept
 start an asynchronous multishot wait, staying armed until cancelled or failed.
 
int cancel (size_t index) noexcept
 cancel the operation stored at the given index, if in flight.
 
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 address family.
 
int type () const noexcept
 get the protocol communication semantic.
 
int protocol () const noexcept
 get socket protocol.
 
int handle () const noexcept
 get socket native handle.
 
- Public Member Functions inherited from join::CompletionHandler
 CompletionHandler ()=default
 create instance.
 
 CompletionHandler (const CompletionHandler &other)=default
 copy constructor.
 
CompletionHandleroperator= (const CompletionHandler &other)=default
 copy assignment operator.
 
 CompletionHandler (CompletionHandler &&other)=default
 move constructor.
 
CompletionHandleroperator= (CompletionHandler &&other)=default
 move assignment operator.
 
virtual ~CompletionHandler ()=default
 destroy instance.
 

Additional Inherited Members

- Static Public Attributes inherited from join::BasicAsyncSocket< Protocol, BasicProactor, OpCount >
static constexpr size_t _opCount
 number of operations in flight.
 
static constexpr size_t _opSize
 size of an operation slot.
 
- Protected Member Functions inherited from join::BasicAsyncRawSocket< Protocol, BasicProactor, 16 >
void dispatch (IoOperation &op, const std::error_code &code, size_t size) noexcept override
 invoke the completion handler of the given operation, then release it.
 
void completeConnect (AsyncWrite *connect, const std::error_code &code) noexcept
 invoke the connect completion handler.
 
void completeRead (AsyncRead *read, const std::error_code &code, size_t size) noexcept
 invoke the read completion handler.
 
void completeWrite (AsyncWrite *write, const std::error_code &code, size_t size) noexcept
 invoke the write completion handler.
 
AsyncReadallocateRead () noexcept
 allocate a read operation in the arena.
 
AsyncWriteallocateWrite () noexcept
 allocate a write operation in the arena.
 
- Protected Member Functions inherited from join::BasicAsyncSocket< Protocol, BasicProactor, OpCount >
 BasicAsyncSocket (BasicProactor &proactor=ProactorThread::proactor())
 create the socket instance.
 
 BasicAsyncSocket (Socket &&sock, BasicProactor &proactor=ProactorThread::proactor())
 create the socket instance adopting an already opened socket.
 
 BasicAsyncSocket (const BasicAsyncSocket &other)=delete
 copy constructor.
 
 BasicAsyncSocket (BasicAsyncSocket &&other) noexcept
 move constructor.
 
void onComplete (IoOperation &op, int result) override
 method called when an operation completes.
 
void onCancel (IoOperation &op, int result) override
 method called when an operation is cancelled.
 
void completeWait (AsyncWait *wait, const std::error_code &code, size_t revents) noexcept
 invoke the wait completion handler.
 
Op * allocateOp () noexcept
 allocate an operation in the arena.
 
void releaseOp (Op *operation) noexcept
 return an operation to the arena.
 
void suspendAll () noexcept
 suspend every operation in flight.
 
void resumeAll () noexcept
 resume every suspended operation, redirecting it to this handler.
 
void cancelAll () noexcept
 cancel every operation in flight.
 
bool pendingAny () const noexcept
 check if at least one operation is in flight or completing.
 
int cancelOp (IoOperation *op) noexcept
 cancel the given operation, if in flight.
 
bool inFlight (const IoOperation &op) const noexcept
 check if an operation is in flight.
 
bool pending (const IoOperation &op) const noexcept
 check if an operation is in flight or completing.
 
- Protected Member Functions inherited from join::CompletionHandler
- Protected Attributes inherited from join::BasicAsyncSocket< Protocol, BasicProactor, OpCount >
BasicProactor_proactor
 proactor driving the operations.
 
Socket _socket
 underlying synchronous socket.
 
OpArena _arena
 operations arena.
 
std::array< std::atomic< IoOperation * >, _opCount_ops
 operations in flight.
 

Detailed Description

template<class Protocol, class Proactor = BasicProactor, size_t OpCount = 16>
class join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >

asynchronous datagram socket class.

Member Typedef Documentation

◆ AsyncRead

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
using join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::AsyncRead = BasicAsyncRead<Protocol, Proactor>

◆ AsyncWrite

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
using join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::AsyncWrite = BasicAsyncWrite<Protocol, Proactor>

◆ Endpoint

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
using join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::Endpoint = typename Protocol::Endpoint

◆ ReadFromHandler

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
using join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::ReadFromHandler = typename AsyncRead::ReadFrom

◆ Socket

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
using join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::Socket = typename Protocol::Socket

◆ WriteHandler

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
using join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::WriteHandler = typename AsyncWrite::Write

Constructor & Destructor Documentation

◆ BasicAsyncDatagramSocket() [1/5]

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::BasicAsyncDatagramSocket ( Proactor & proactor = ProactorThread::proactor ())
inlineexplicit

create the socket instance.

Parameters
proactorproactor driving the operations.

◆ BasicAsyncDatagramSocket() [2/5]

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::BasicAsyncDatagramSocket ( int ttl,
Proactor & proactor = ProactorThread::proactor () )
inlineexplicit

create the socket instance specifying the time to live.

Parameters
ttlpacket time to live.
proactorproactor driving the operations.

◆ BasicAsyncDatagramSocket() [3/5]

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::BasicAsyncDatagramSocket ( Socket && sock,
Proactor & proactor = ProactorThread::proactor () )
inlineexplicit

create the socket instance adopting an already opened socket.

Parameters
socksocket to adopt.
proactorproactor driving the operations.

◆ BasicAsyncDatagramSocket() [4/5]

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::BasicAsyncDatagramSocket ( const BasicAsyncDatagramSocket< Protocol, Proactor, OpCount > & other)
delete

copy constructor.

Parameters
otherother object to copy.

◆ BasicAsyncDatagramSocket() [5/5]

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::BasicAsyncDatagramSocket ( BasicAsyncDatagramSocket< Protocol, Proactor, OpCount > && other)
defaultnoexcept

move constructor.

Parameters
otherother object to move.

Member Function Documentation

◆ asyncReadFrom()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
ssize_t join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::asyncReadFrom ( char * data,
size_t maxSize,
Endpoint & endpoint,
ReadFromHandler handler,
bool flush = true,
bool link = false )
inlinenoexcept

start an asynchronous read, reporting the endpoint the data are coming from.

Parameters
databuffer used to store the data received, valid until the handler is invoked.
maxSizemaximum number of bytes to read.
endpointendpoint from where data are coming, valid until the handler is invoked.
handlerhandler invoked on completion.
flushflush the submission queue.
linklink this operation to the next one submitted.
Returns
index of the operation on success, -1 on failure.

◆ asyncReadFromMulti()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
ssize_t join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::asyncReadFromMulti ( uint16_t group,
ReadFromHandler handler,
bool flush = true )
inlinenoexcept

start an asynchronous multishot read, reporting the endpoint the data are coming from.

Parameters
groupprovided buffer group to receive into, registered on the proactor.
handlerhandler invoked on each completion, buffer and endpoint valid during the call only.
flushflush the submission queue.
Returns
index of the operation on success, -1 on failure.

◆ asyncWriteTo()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
ssize_t join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::asyncWriteTo ( const char * data,
size_t size,
Endpoint & endpoint,
WriteHandler handler,
bool flush = true,
bool link = false )
inlinenoexcept

start an asynchronous write to the given endpoint.

Parameters
datadata buffer to send, valid until the handler is invoked.
sizenumber of bytes to write.
endpointendpoint where to write the data, valid until the handler is invoked.
handlerhandler invoked on completion.
flushflush the submission queue.
linklink this operation to the next one submitted.
Returns
index of the operation on success, -1 on failure.

◆ connect()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
int join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::connect ( const Endpoint & endpoint)
inlinenoexcept

assign the default remote endpoint for this socket.

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

◆ connected()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
bool join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::connected ( ) const
inlinenoexcept

check if the socket is connected.

Returns
true if connected, false otherwise.

◆ disconnect()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
int join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::disconnect ( )
inlinenoexcept

remove the default remote endpoint.

Returns
0 on success, -1 on failure.

◆ mtu()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
int join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::mtu ( ) const
inlinenoexcept

get socket mtu.

Returns
mtu on success, -1 on failure.

◆ operator=() [1/2]

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
BasicAsyncDatagramSocket & join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::operator= ( BasicAsyncDatagramSocket< Protocol, Proactor, OpCount > && other)
defaultnoexcept

move assignment operator.

Parameters
otherother object to assign.
Returns
assigned object.

◆ operator=() [2/2]

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
BasicAsyncDatagramSocket & join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::operator= ( const BasicAsyncDatagramSocket< Protocol, Proactor, OpCount > & other)
delete

copy assignment operator.

Parameters
otherother object to assign.
Returns
assigned object.

◆ remoteEndpoint()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
const Endpoint & join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::remoteEndpoint ( ) const
inlinenoexcept

determine the remote endpoint associated with this socket.

Returns
remote endpoint.

◆ ttl()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
int join::BasicAsyncDatagramSocket< Protocol, Proactor, OpCount >::ttl ( ) const
inlinenoexcept

returns the Time-To-Live value.

Returns
the Time-To-Live value.

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