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

asynchronous stream socket class. More...

#include <async_stream_socket.hpp>

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

Public Types

using Socket = typename Protocol::Socket
 
using Endpoint = typename Protocol::Endpoint
 
using AsyncWrite = BasicAsyncWrite<Protocol, Proactor>
 
using ConnectHandler = typename AsyncWrite::Connect
 
- 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

 BasicAsyncStreamSocket (Proactor &proactor=ProactorThread::proactor())
 create the socket instance.
 
 BasicAsyncStreamSocket (Socket &&sock, Proactor &proactor=ProactorThread::proactor())
 create the socket instance adopting an already connected socket.
 
 BasicAsyncStreamSocket (const BasicAsyncStreamSocket &other)=delete
 copy constructor.
 
BasicAsyncStreamSocketoperator= (const BasicAsyncStreamSocket &other)=delete
 copy assignment operator.
 
 BasicAsyncStreamSocket (BasicAsyncStreamSocket &&other) noexcept=default
 move constructor.
 
BasicAsyncStreamSocketoperator= (BasicAsyncStreamSocket &&other) noexcept=default
 move assignment operator.
 
int asyncConnect (const Endpoint &endpoint, ConnectHandler handler) noexcept
 start an asynchronous connection to the given endpoint.
 
const EndpointremoteEndpoint () const noexcept
 determine the remote endpoint associated with this socket.
 
bool connected () noexcept
 check if the socket is connected.
 
bool connecting () const noexcept
 check if the socket is connecting.
 
int mtu () const noexcept
 get the path maximum transmission unit.
 
- 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::BasicAsyncStreamSocket< Protocol, Proactor, OpCount >

asynchronous stream socket class.

Member Typedef Documentation

◆ AsyncWrite

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

◆ ConnectHandler

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

◆ Endpoint

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

◆ Socket

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

Constructor & Destructor Documentation

◆ BasicAsyncStreamSocket() [1/4]

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

create the socket instance.

Parameters
proactorproactor driving the operations.

◆ BasicAsyncStreamSocket() [2/4]

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

create the socket instance adopting an already connected socket.

Parameters
socksocket to adopt.
proactorproactor driving the operations.

◆ BasicAsyncStreamSocket() [3/4]

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

copy constructor.

Parameters
otherother object to copy.

◆ BasicAsyncStreamSocket() [4/4]

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

move constructor.

Parameters
otherother object to move.

Member Function Documentation

◆ asyncConnect()

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
int join::BasicAsyncStreamSocket< Protocol, Proactor, OpCount >::asyncConnect ( const Endpoint & endpoint,
ConnectHandler handler )
inlinenoexcept

start an asynchronous connection to the given endpoint.

Parameters
endpointendpoint to connect to.
handlerhandler invoked on completion.
Returns
0 on success, -1 on failure.

◆ connected()

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

check if the socket is connected.

Returns
true if connected, false otherwise.

◆ connecting()

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

check if the socket is connecting.

Returns
true if connecting, false otherwise.

◆ mtu()

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

get the path maximum transmission unit.

Returns
the path maximum transmission unit, -1 on failure.

◆ operator=() [1/2]

template<class Protocol , class Proactor = BasicProactor, size_t OpCount = 16>
BasicAsyncStreamSocket & join::BasicAsyncStreamSocket< Protocol, Proactor, OpCount >::operator= ( BasicAsyncStreamSocket< 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>
BasicAsyncStreamSocket & join::BasicAsyncStreamSocket< Protocol, Proactor, OpCount >::operator= ( const BasicAsyncStreamSocket< 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::BasicAsyncStreamSocket< Protocol, Proactor, OpCount >::remoteEndpoint ( ) const
inlinenoexcept

determine the remote endpoint associated with this socket.

Returns
remote endpoint.

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