25#ifndef JOIN_CORE_ASYNC_STREAM_SOCKET_HPP
26#define JOIN_CORE_ASYNC_STREAM_SOCKET_HPP
33#include <system_error>
41 template <
class Protocol,
class ProactorType,
size_t OpCount>
42 class BasicAsyncStreamSocket :
public BasicAsyncRawSocket<Protocol, ProactorType, OpCount>
45 using Socket =
typename Protocol::Socket;
109 if (this->
_socket.connected () || this->_socket.connecting ())
115 if (!this->
_socket.opened () && (this->_socket.open (endpoint.protocol ()) == -1))
129 this->
_socket._state = Socket::Connecting;
130 this->
_socket._remote = endpoint;
133 this->_socket._remote.length (),
this);
154 return this->
_socket.remoteEndpoint ();
163 return this->
_socket.connected ();
172 return this->
_socket.connecting ();
asynchronous raw socket class.
Definition protocol.hpp:88
AsyncWrite * allocateWrite() noexcept
Definition async_raw_socket.hpp:588
Socket _socket
Definition async_socket.hpp:657
void releaseOperation(Op *operation) noexcept
Definition async_socket.hpp:539
BasicProactor * _proactor
Definition async_socket.hpp:654
OpAllocator _allocator
Definition async_socket.hpp:660
asynchronous stream socket class.
Definition protocol.hpp:94
BasicAsyncStreamSocket(Socket &&sock, ProactorType &proactor=ProactorThread::proactor())
create the socket instance adopting an already connected socket.
Definition async_stream_socket.hpp:64
typename Protocol::Socket Socket
Definition async_stream_socket.hpp:45
BasicAsyncStreamSocket(ProactorType &proactor=ProactorThread::proactor())
create the socket instance.
Definition async_stream_socket.hpp:54
bool connected() noexcept
check if the socket is connected.
Definition async_stream_socket.hpp:161
BasicAsyncStreamSocket(const BasicAsyncStreamSocket &other)=delete
copy constructor.
bool connecting() const noexcept
check if the socket is connecting.
Definition async_stream_socket.hpp:170
typename Protocol::Endpoint Endpoint
Definition async_stream_socket.hpp:46
BasicAsyncStreamSocket(BasicAsyncStreamSocket &&other) noexcept=default
move constructor.
int mtu() const noexcept
get the path maximum transmission unit.
Definition async_stream_socket.hpp:179
int asyncConnect(ConnectHandler handler, const Endpoint &endpoint) noexcept
start an asynchronous connection to the given endpoint.
Definition async_stream_socket.hpp:101
const Endpoint & remoteEndpoint() const noexcept
determine the remote endpoint associated with this socket.
Definition async_stream_socket.hpp:152
typename AsyncWrite::Connect ConnectHandler
Definition async_stream_socket.hpp:48
BasicAsyncStreamSocket & operator=(const BasicAsyncStreamSocket &other)=delete
copy assignment operator.
static BasicProactor & proactor()
get the Proactor instance owned by the singleton ProactorThread.
Definition proactor.hpp:1053
int submit(IoOperation &op, bool flush=false, bool sync=false) noexcept
submit an asynchronous operation to the proactor.
Definition proactor.hpp:741
bool hasBackend() const noexcept
check if the slab allocator still owns a memory region.
Definition slab_allocator.hpp:444
Definition acceptor.hpp:32
std::error_code make_error_code(join::Errc code) noexcept
Create an std::error_code object.
Definition error.cpp:195
asynchronous write operation.
Definition async_operation.hpp:121
Connect connectHandler
handler invoked on connection completion.
Definition async_operation.hpp:132
Function< void(const std::error_code &), 16 > Connect
handler invoked on connection completion.
Definition async_operation.hpp:123
IoOperation op
operation submitted to the proactor.
Definition async_operation.hpp:129
static IoOperation makeConnect(int fd, const sockaddr *addr, socklen_t addrlen, CompletionHandler *handler) noexcept
build a connect operation.
Definition io_operation.cpp:144
std::atomic< State > state
operation state.
Definition io_operation.hpp:404
#define JOIN_UNLIKELY(x)
Definition utils.hpp:51