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

asynchronous raw socket class. More...

#include <async_raw_socket.hpp>

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

Public Types

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

Public Member Functions

 BasicAsyncRawSocket (Proactor &proactor=ProactorThread::proactor())
 create the socket instance.
 
 BasicAsyncRawSocket (Socket &&sock, Proactor &proactor=ProactorThread::proactor())
 create the socket instance adopting an already opened socket.
 
 BasicAsyncRawSocket (const BasicAsyncRawSocket &other)=delete
 copy constructor.
 
BasicAsyncRawSocketoperator= (const BasicAsyncRawSocket &other)=delete
 copy assignment operator.
 
 BasicAsyncRawSocket (BasicAsyncRawSocket &&other) noexcept
 move constructor.
 
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, 16 >
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.
 

Protected Member Functions

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, 16 >
 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

Additional Inherited Members

- Static Public Attributes inherited from join::BasicAsyncSocket< Protocol, BasicProactor, 16 >
static constexpr size_t _opCount
 number of operations in flight.
 
static constexpr size_t _opSize
 size of an operation slot.
 
- Protected Attributes inherited from join::BasicAsyncSocket< Protocol, BasicProactor, 16 >
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::BasicAsyncRawSocket< Protocol, Proactor, OpCount >

asynchronous raw socket class.

Member Typedef Documentation

◆ AsyncRead

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

◆ AsyncWrite

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

◆ ConnectHandler

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
using join::BasicAsyncRawSocket< Protocol, Proactor, OpCount >::ConnectHandler = typename AsyncWrite::Connect

◆ Endpoint

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

◆ Option

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

◆ ReadFromHandler

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

◆ ReadHandler

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
using join::BasicAsyncRawSocket< Protocol, Proactor, OpCount >::ReadHandler = typename AsyncRead::Read

◆ Socket

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

◆ WriteHandler

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

Constructor & Destructor Documentation

◆ BasicAsyncRawSocket() [1/4]

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

create the socket instance.

Parameters
proactorproactor driving the operations.

◆ BasicAsyncRawSocket() [2/4]

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

create the socket instance adopting an already opened socket.

Parameters
socksocket to adopt.
proactorproactor driving the operations.

◆ BasicAsyncRawSocket() [3/4]

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

copy constructor.

Parameters
otherother object to copy.

◆ BasicAsyncRawSocket() [4/4]

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

move constructor.

Parameters
otherother object to move.

◆ ~BasicAsyncRawSocket()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
join::BasicAsyncRawSocket< Protocol, Proactor, OpCount >::~BasicAsyncRawSocket ( )
inline

destroy the socket instance.

Member Function Documentation

◆ allocateRead()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
AsyncRead * join::BasicAsyncRawSocket< Protocol, Proactor, OpCount >::allocateRead ( )
inlineprotectednoexcept

allocate a read operation in the arena.

Returns
allocated read operation, or nullptr if the arena is exhausted.

◆ allocateWrite()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
AsyncWrite * join::BasicAsyncRawSocket< Protocol, Proactor, OpCount >::allocateWrite ( )
inlineprotectednoexcept

allocate a write operation in the arena.

Returns
allocated write operation, or nullptr if the arena is exhausted.

◆ asyncRead()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
ssize_t join::BasicAsyncRawSocket< Protocol, Proactor, OpCount >::asyncRead ( char * data,
size_t maxSize,
ReadHandler handler,
bool flush = true,
bool link = false )
inlinenoexcept

start an asynchronous read.

Parameters
databuffer used to store the data received, valid until the handler is invoked.
maxSizemaximum number of bytes to read.
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.

◆ asyncReadMulti()

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

start an asynchronous multishot read, staying armed until cancelled or failed.

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

◆ asyncWrite()

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

start an asynchronous write.

Parameters
datadata buffer to send, valid until the handler is invoked.
sizenumber of bytes to write.
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.

◆ bind()

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

assign the specified endpoint to the socket.

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

◆ bindToDevice()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
int join::BasicAsyncRawSocket< Protocol, Proactor, OpCount >::bindToDevice ( const std::string & device)
inlinenoexcept

assign the specified device to the socket.

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

◆ cancelConnect()

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

cancel the connect operation in flight, if any.

Returns
0 on success, -1 on failure.

◆ canRead()

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

get the number of readable bytes.

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

◆ completeConnect()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
void join::BasicAsyncRawSocket< Protocol, Proactor, OpCount >::completeConnect ( AsyncWrite * connect,
const std::error_code & code )
inlineprotectednoexcept

invoke the connect completion handler.

Parameters
codeerror code reported by the kernel.

◆ completeRead()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
void join::BasicAsyncRawSocket< Protocol, Proactor, OpCount >::completeRead ( AsyncRead * read,
const std::error_code & code,
size_t size )
inlineprotectednoexcept

invoke the read completion handler.

Parameters
readcompleted read operation.
codeerror code reported by the kernel.
sizenumber of bytes received.

◆ completeWrite()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
void join::BasicAsyncRawSocket< Protocol, Proactor, OpCount >::completeWrite ( AsyncWrite * write,
const std::error_code & code,
size_t size )
inlineprotectednoexcept

invoke the write completion handler.

Parameters
codeerror code reported by the kernel.
sizenumber of bytes sent.

◆ dispatch()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
void join::BasicAsyncRawSocket< Protocol, Proactor, OpCount >::dispatch ( IoOperation & op,
const std::error_code & code,
size_t size )
inlineoverrideprotectedvirtualnoexcept

invoke the completion handler of the given operation, then release it.

Parameters
opcompleted operation.
codeerror code reported by the kernel.
sizenumber of bytes transferred.

Reimplemented from join::BasicAsyncSocket< Protocol, BasicProactor, 16 >.

◆ operator=() [1/2]

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

move assignment operator.

Parameters
otherother object to assign.
Returns
assigned object.

◆ operator=() [2/2]

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

copy assignment operator.

Parameters
otherother object to assign.
Returns
assigned object.

◆ setOption()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
int join::BasicAsyncRawSocket< Protocol, Proactor, OpCount >::setOption ( Option option,
int value )
inlinenoexcept

set the given option to the given value.

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

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