21#include "flow/error/error.hpp"
22#include <boost/move/make_unique.hpp>
39 flow::log::Log_context(sync_io_core_moved.get_logger(),
Log_component::S_TRANSPORT),
41 m_worker(get_logger(),
45 flow::util::ostream_op_string(
"Sck-", sync_io_core_moved.nickname())),
47 m_sync_io(std::move(sync_io_core_moved))
51 using flow::async::reset_this_thread_pinning;
53 m_worker.start(reset_this_thread_pinning);
60 {
return Asio_waitable_native_handle{*(
m_worker.task_engine())}; });
61 assert(ok &&
"Did you break contract by passing-in a non-fresh sync_io core object to ctor?");
66 FLOW_LOG_TRACE(
"Socket stream [" << *
this <<
"]: Created (NULL state).");
80 std::move(native_peer_socket_moved)},
83 using flow::util::ostream_op_string;
87 const auto log_pfx = ostream_op_string(
"Sck-",
nickname());
91 FLOW_LOG_TRACE(
"Socket stream [" << *
this <<
"]: Created (PEER state) directly from pre-opened native handle.");
98 using flow::util::ostream_op_string;
102 const auto log_pfx = ostream_op_string(
"Sck-",
nickname());
106 FLOW_LOG_TRACE(
"Socket stream [" << *
this <<
"]: "
107 "Created (PEER state) by adopting fresh sync_io::Native_socket_stream core.");
112 using flow::async::Single_thread_task_loop;
113 using flow::async::reset_thread_pinning;
114 using flow::util::ostream_op_string;
118 FLOW_LOG_INFO(
"Socket stream [" << *
this <<
"]: Shutting down. All our "
119 "internal async handlers will be canceled; and worker thread will be joined.");
167 FLOW_LOG_INFO(
"Socket stream [" << *
this <<
"]: Continuing shutdown. Next we will run pending handlers from some "
168 "other thread. In this user thread we will await those handlers' completion and then return.");
170 Single_thread_task_loop one_thread{get_logger(), ostream_op_string(
"SckDeinit-",
nickname())};
171 one_thread.start([&]()
173 reset_thread_pinning(get_logger());
175 FLOW_LOG_INFO(
"Socket stream [" << *
this <<
"]: "
176 "In transient finisher thread: Shall run all pending internal handlers (typically none).");
178 const auto task_engine =
m_worker.task_engine();
179 task_engine->restart();
180 const auto count = task_engine->poll();
183 FLOW_LOG_INFO(
"Socket stream [" << *
this <<
"]: "
184 "In transient finisher thread: Ran [" << count <<
"] internal handlers after all.");
190 FLOW_LOG_INFO(
"Transient finisher exiting. (Send-ops and receive-ops de-init may follow.)");
197 using flow::util::ostream_op_string;
199 FLOW_ERROR_EXEC_AND_THROW_ON_ERROR(
bool,
sync_connect, absolute_name, _1);
211 const auto log_pfx = ostream_op_string(
"Sck-",
nickname());
238 return os <<
'[' << val.
nickname() <<
"]@" <<
static_cast<const void*
>(&val);
324 flow::async::Task_asio_err_sz&& on_done_func)
328 (target_hndl, target_meta_blob, std::move(on_done_func)),
334 flow::async::Task_asio_err_sz&& on_done_func)
394 using flow::util::ostream_op_string;
395 using flow::async::reset_this_thread_pinning;
397 FLOW_LOG_TRACE(
"Socket stream [" << *
this <<
"]: Releasing idle-state object to new socket-stream core object.");
415 auto prev_worker = std::move(
m_worker);
419 = boost::movelib::make_unique<flow::async::Single_thread_task_loop>
420 (core.get_logger(), core.nickname());
421 m_worker->start(reset_this_thread_pinning);
428 {
return Asio_waitable_native_handle{*(
m_worker->task_engine())}; });
429 assert(ok &&
"Should work if m_sync_io.release() worked as advertised.");
static constexpr size_t S_MAX_META_BLOB_LENGTH
The maximum length of a blob that can be sent by the protocol internally used by sync_io::Native_sock...
Internal, non-movable pImpl-lite implementation of Native_socket_stream class.
bool sync_connect(const Shared_name &absolute_name, Error_code *err_code)
See Native_socket_stream counterpart.
void native_handle_receive_stats_reset()
See Native_socket_stream counterpart.
const std::string & nickname() const
See Native_socket_stream counterpart.
bool send_native_handle(Native_handle hndl_or_null, const util::Blob_const &meta_blob, Error_code *err_code)
See Native_socket_stream counterpart.
Blob_rcv_stats native_handle_receive_stats() const
See Native_socket_stream counterpart.
const util::Process_credentials & remote_peer_process_credentials(Error_code *err_code) const
See Native_socket_stream counterpart.
Blob_snd_stats blob_send_stats() const
See Native_socket_stream counterpart.
bool auto_ping(util::Fine_duration period)
See Native_socket_stream counterpart.
void blob_send_stats_reset()
See Native_socket_stream counterpart.
Blob_rcv_stats blob_receive_stats() const
See Native_socket_stream counterpart.
bool idle_timer_run(util::Fine_duration timeout)
See Native_socket_stream counterpart.
sync_io::Native_socket_stream m_sync_io
The core Native_socket_stream engine, implementing the sync_io pattern (see util::sync_io doc header)...
bool async_end_sending(flow::async::Task_asio_err &&on_done_func)
See Native_socket_stream counterpart.
void blob_receive_stats_reset()
See Native_socket_stream counterpart.
std::optional< sync_io::Async_adapter_sender< decltype(m_sync_io)> > m_snd_sync_io_adapter
Null until PEER state, this handles ~all send-ops logic in that state.
size_t receive_blob_max_size() const
See Native_socket_stream counterpart.
Blob_snd_stats native_handle_send_stats() const
See Native_socket_stream counterpart.
size_t send_blob_max_size() const
See Native_socket_stream counterpart.
void native_handle_send_stats_reset()
See Native_socket_stream counterpart.
std::optional< sync_io::Async_adapter_receiver< decltype(m_sync_io)> > m_rcv_sync_io_adapter
Null until PEER state, this handles ~all receive-ops logic in that state.
size_t receive_meta_blob_max_size() const
See Native_socket_stream counterpart.
Native_socket_stream_impl(flow::log::Logger *logger_ptr, util::String_view nickname_str)
See Native_socket_stream counterpart.
bool end_sending()
See Native_socket_stream counterpart.
bool async_receive_blob(const util::Blob_mutable &target_blob, flow::async::Task_asio_err_sz &&on_done_func)
See Native_socket_stream counterpart.
bool async_receive_native_handle(Native_handle *target_hndl, const util::Blob_mutable &target_meta_blob, flow::async::Task_asio_err_sz &&on_done_func)
See Native_socket_stream counterpart.
~Native_socket_stream_impl()
See Native_socket_stream counterpart.
bool send_blob(const util::Blob_const &blob, Error_code *err_code)
See Native_socket_stream counterpart.
size_t send_meta_blob_max_size() const
See Native_socket_stream counterpart.
flow::async::Single_thread_task_loop m_worker
Single-thread worker pool for all internal async work in both directions.
Implements both Native_handle_sender and Native_handle_receiver concepts by using a Unix domain socke...
Implements both sync_io::Native_handle_sender and sync_io::Native_handle_receiver concepts by using a...
const util::Process_credentials & remote_peer_process_credentials(Error_code *err_code=nullptr) const
See transport::Native_socket_stream counterpart.
const std::string & nickname() const
Returns nickname, a brief string suitable for logging.
bool sync_connect(const Shared_name &absolute_name, Error_code *err_code=nullptr)
Identical to Async_io_obj counterpart.
size_t receive_blob_max_size() const
Implements Blob_receiver API per contract.
size_t send_blob_max_size() const
Implements Blob_sender API per contract.
bool replace_event_wait_handles(const Create_ev_wait_hndl_func &create_ev_wait_hndl_func)
Implements Native_handle_sender and Native_handle_receiver APIs at the same time, per their concept c...
A process's credentials (PID, UID, GID as of this writing).
String-wrapping abstraction representing a name uniquely distinguishing a kernel-persistent entity fr...
Useful if using the sync_io pattern within a user event loop built on boost.asio (optionally with flo...
Flow-IPC module providing transmission of structured messages and/or low-level blobs (and more) betwe...
std::ostream & operator<<(std::ostream &os, const Generic_msg_batch_in< Msg_resource_t, NO_HNDLS > &val)
Prints string representation of the given Generic_msg_batch_in to the given ostream.
boost::shared_ptr< Task > Task_ptr
Short-hand for ref-counted pointer to a Function<> that takes no arguments and returns nothing; in pa...
boost::asio::mutable_buffer Blob_mutable
Short-hand for a mutable blob somewhere in memory, stored as exactly a void* and a size_t.
flow::Fine_duration Fine_duration
Short-hand for Flow's Fine_duration.
boost::asio::const_buffer Blob_const
Short-hand for an immutable blob somewhere in memory, stored as exactly a void const * and a size_t.
flow::util::String_view String_view
Short-hand for Flow's String_view.
Log_component
The flow::log::Component payload enumeration containing various log components used by Flow-IPC inter...
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.
Cumulative stats from the incoming-direction (receive) pipe of a Blob_receiver or Native_handle_recei...
Cumulative stats from the outgoing-direction (send) pipe of a Blob_sender or Native_handle_sender con...
A monolayer-thin wrapper around a native handle, a/k/a descriptor a/k/a FD.