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 Proactor,
size_t OpCount>
42 class BasicAsyncStreamSocket :
public BasicAsyncRawSocket<Protocol, Proactor, 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 ();
bool hasBackend() const noexcept
check if the arena still owns a memory region.
Definition allocator.hpp:487
asynchronous raw socket class.
Definition protocol.hpp:85
AsyncWrite * allocateWrite() noexcept
Definition async_raw_socket.hpp:579
Socket _socket
Definition async_socket.hpp:629
void releaseOp(Op *operation) noexcept
Definition async_socket.hpp:525
OpArena _arena
Definition async_socket.hpp:632
BasicProactor * _proactor
Definition async_socket.hpp:626
asynchronous stream socket class.
Definition protocol.hpp:91
typename AsyncWrite::Connect ConnectHandler
Definition async_stream_socket.hpp:48
BasicAsyncStreamSocket(Socket &&sock, Proactor &proactor=ProactorThread::proactor())
create the socket instance adopting an already connected socket.
Definition async_stream_socket.hpp:64
BasicAsyncStreamSocket & operator=(const BasicAsyncStreamSocket &other)=delete
copy assignment operator.
const Endpoint & remoteEndpoint() const noexcept
determine the remote endpoint associated with this socket.
Definition async_stream_socket.hpp:152
int mtu() const noexcept
get the path maximum transmission unit.
Definition async_stream_socket.hpp:179
BasicAsyncStreamSocket(BasicAsyncStreamSocket &&other) noexcept=default
move constructor.
typename Protocol::Socket Socket
Definition async_stream_socket.hpp:45
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
int asyncConnect(const Endpoint &endpoint, ConnectHandler handler) noexcept
start an asynchronous connection to the given endpoint.
Definition async_stream_socket.hpp:101
BasicAsyncStreamSocket(const BasicAsyncStreamSocket &other)=delete
copy constructor.
BasicAsyncStreamSocket(Proactor &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
static BasicProactor & proactor()
get the Proactor instance owned by the singleton ProactorThread.
Definition proactor.hpp:982
basic proactor class.
Definition proactor.hpp:156
int submit(IoOperation &op, bool flush=false, bool sync=false) noexcept
submit an asynchronous operation to the proactor.
Definition proactor.hpp:655
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:119
Function< void(const std::error_code &), 16 > Connect
handler invoked on connection completion.
Definition async_operation.hpp:121
Connect connectHandler
handler invoked on connection completion.
Definition async_operation.hpp:130
IoOperation op
operation submitted to the proactor.
Definition async_operation.hpp:127
static IoOperation makeConnect(int fd, const sockaddr *addr, socklen_t addrlen, CompletionHandler *handler) noexcept
build a connect operation.
Definition io_operation.cpp:136
std::atomic< State > state
operation state.
Definition io_operation.hpp:392
#define JOIN_UNLIKELY(x)
Definition utils.hpp:46