|
join 1.0
lightweight network framework library
|
basic asynchronous socket class. More...
#include <async_socket.hpp>


Public Types | |
| using | Socket = typename Protocol::Socket |
| using | Endpoint = typename Protocol::Endpoint |
| using | AsyncWait = BasicAsyncWait<Protocol, Proactor> |
| using | WaitHandler = typename AsyncWait::Wait |
| using | OpArena = LocalMem::Allocator<_opCount, _opSize> |
Public Member Functions | |
| BasicAsyncSocket & | operator= (const BasicAsyncSocket &other)=delete |
| copy assignment operator. | |
| BasicAsyncSocket & | operator= (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. | |
| template<size_t Count, size_t Size> | |
| 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. | |
| CompletionHandler & | operator= (const CompletionHandler &other)=default |
| copy assignment operator. | |
| CompletionHandler (CompletionHandler &&other)=default | |
| move constructor. | |
| CompletionHandler & | operator= (CompletionHandler &&other)=default |
| move assignment operator. | |
| virtual | ~CompletionHandler ()=default |
| destroy instance. | |
Static Public Attributes | |
| static constexpr size_t | _opCount = OpCount |
| number of operations in flight. | |
| static constexpr size_t | _opSize = nextPow2 (AsyncOp<Protocol, Proactor>::maxSize) |
| size of an operation slot. | |
Protected Member Functions | |
| BasicAsyncSocket (Proactor &proactor=ProactorThread::proactor()) | |
| create the socket instance. | |
| BasicAsyncSocket (Socket &&sock, Proactor &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. | |
| virtual void | dispatch (IoOperation &op, const std::error_code &code, size_t size) noexcept |
| invoke the completion handler of the given operation, then release it. | |
| void | completeWait (AsyncWait *wait, const std::error_code &code, size_t revents) noexcept |
| invoke the wait completion handler. | |
| template<class Op > | |
| Op * | allocateOp () noexcept |
| allocate an operation in the arena. | |
| template<class Op > | |
| 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 | |
| Proactor * | _proactor |
| proactor driving the operations. | |
| Socket | _socket |
| underlying synchronous socket. | |
| OpArena | _arena |
| operations arena. | |
| std::array< std::atomic< IoOperation * >, _opCount > | _ops {} |
| operations in flight. | |
basic asynchronous socket class.
| using join::BasicAsyncSocket< Protocol, Proactor, OpCount >::AsyncWait = BasicAsyncWait<Protocol, Proactor> |
| using join::BasicAsyncSocket< Protocol, Proactor, OpCount >::Endpoint = typename Protocol::Endpoint |
| using join::BasicAsyncSocket< Protocol, Proactor, OpCount >::OpArena = LocalMem::Allocator<_opCount, _opSize> |
| using join::BasicAsyncSocket< Protocol, Proactor, OpCount >::Socket = typename Protocol::Socket |
| using join::BasicAsyncSocket< Protocol, Proactor, OpCount >::WaitHandler = typename AsyncWait::Wait |
|
inlineexplicitprotected |
create the socket instance.
| proactor | proactor driving the operations. |
|
inlineexplicitprotected |
create the socket instance adopting an already opened socket.
| sock | socket to adopt. |
| proactor | proactor driving the operations. |
|
protecteddelete |
copy constructor.
| other | other object to copy. |
|
inlineprotectednoexcept |
move constructor.
| other | other object to move. |
|
inline |
destroy the socket instance.
|
inlineprotectednoexcept |
allocate an operation in the arena.
|
inlinenoexcept |
start an asynchronous wait for the socket to become ready in one direction.
| wantRead | wait until the socket is readable. |
| wantWrite | wait until the socket is writable. |
| handler | handler invoked on completion. |
| flush | flush the submission queue. |
|
inlinenoexcept |
start an asynchronous multishot wait, staying armed until cancelled or failed.
| wantRead | wait until the socket is readable. |
| wantWrite | wait until the socket is writable. |
| handler | handler invoked on each completion, it must drain the socket or be invoked again at once. |
| flush | flush the submission queue. |
|
inlinenoexcept |
cancel the operation stored at the given index, if in flight.
| index | index of the operation to cancel. |
|
inlineprotectednoexcept |
cancel every operation in flight.
|
inlineprotectednoexcept |
cancel the given operation, if in flight.
| op | operation to cancel. |
|
inlinenoexcept |
close the socket, cancelling the operations in flight.
|
inlineprotectednoexcept |
invoke the wait completion handler.
| wait | completed wait operation. |
| code | error code reported by the kernel. |
| revents | ready events. |
|
inlineprotectedvirtualnoexcept |
invoke the completion handler of the given operation, then release it.
| op | completed operation. |
| code | error code reported by the kernel. |
| size | number of bytes transferred, or ready events. |
Reimplemented in join::BasicAsyncRawSocket< Protocol, Proactor, OpCount >, and join::BasicAsyncRawSocket< Protocol, BasicProactor, 16 >.
|
inlinenoexcept |
get address family.
|
inlinenoexcept |
get socket native handle.
|
inlineprotectednoexcept |
check if an operation is in flight.
| op | operation to check. |
|
inlinenoexcept |
determine the local endpoint associated with this socket.
|
inlineoverrideprotectedvirtual |
method called when an operation is cancelled.
| op | cancelled operation. |
| result | negative errno. |
Reimplemented from join::CompletionHandler.
|
inlineoverrideprotectedvirtual |
method called when an operation completes.
| op | completed operation. |
| result | number of bytes transferred, or negative errno. |
Reimplemented from join::CompletionHandler.
|
inlinenoexcept |
open socket using the given protocol.
| protocol | protocol to use. |
|
inlinenoexcept |
check if the socket is opened.
|
inlinenoexcept |
move assignment operator.
| other | other object to assign. |
|
delete |
copy assignment operator.
| other | other object to assign. |
|
inlineprotectednoexcept |
check if an operation is in flight or completing.
| op | operation to check. |
|
inlineprotectednoexcept |
check if at least one operation is in flight or completing.
|
inlinenoexcept |
get socket protocol.
|
inline |
register a provided buffer ring on the proactor driving this socket.
| group | buffer group id. |
| arena | arena owning the buffers, reserved until the ring is unregistered, must outlive the proactor. |
| std::system_error | if the descriptor ring cannot be mapped. |
|
inlineprotectednoexcept |
return an operation to the arena.
| operation | operation to release. |
|
inlineprotectednoexcept |
resume every suspended operation, redirecting it to this handler.
|
inlineprotectednoexcept |
suspend every operation in flight.
|
inlinenoexcept |
get the protocol communication semantic.
|
inline |
unregister a provided buffer ring from the proactor driving this socket.
| group | buffer group id. |
|
protected |
operations arena.
|
staticconstexpr |
number of operations in flight.
|
protected |
operations in flight.
|
staticconstexpr |
size of an operation slot.
|
protected |
proactor driving the operations.
|
protected |
underlying synchronous socket.