23#include <flow/common.hpp>
33# error "Flow-IPC must define Opt_peer_process_credentials w/ Linux SO_PEERCRED semantics. Build in Linux only."
91 template<
typename Protocol>
108 template<
typename Protocol>
125 template<
typename Protocol>
142 template<
typename Protocol>
161 template<
typename Protocol>
162 void resize(
const Protocol& proto,
size_t new_size_but_really_must_equal_current)
const;
169template<
typename Task_err>
174 Task_err&& on_sent_or_error)
177 using flow::util::buffers_dump_string;
179 assert(peer_socket_ptr);
180 assert((!payload_hndl.
null()) && (payload_blob.size() != 0));
182 auto& peer_socket = *peer_socket_ptr;
184 FLOW_LOG_SET_CONTEXT(logger_ptr, Log_component::S_TRANSPORT);
186 FLOW_LOG_TRACE(
"Starting: Via connected local peer socket, will send handle [" << payload_hndl <<
"] with "
187 "blob of size [" << payload_blob.size() <<
"] "
188 "located @ [" << payload_blob.data() <<
"].");
191 FLOW_LOG_DATA(
"Starting: Blob contents are "
192 "[" << buffers_dump_string(payload_blob,
" ") <<
"].");
221 peer_socket.async_wait
222 (Peer_socket::wait_write,
223 [logger_ptr, payload_hndl, payload_blob, peer_socket_ptr,
224 on_sent_or_error = std::move(on_sent_or_error)]
228 std::move(on_sent_or_error));
232template<
typename Task_err_blob,
typename Target_payload_blob_func,
typename Should_
interrupt_func>
234 (flow::log::Logger* logger_ptr,
Peer_socket* peer_socket,
235 Target_payload_blob_func&& target_payload_blob_func, Should_interrupt_func&& should_interrupt_func,
236 Task_err_blob&& on_rcvd_or_error)
242 FLOW_LOG_SET_CONTEXT(logger_ptr, Log_component::S_TRANSPORT);
243 FLOW_LOG_TRACE(
"Starting: Connected local peer socket wants to read 1+ bytes to some currently-unknown location "
244 "TBD when at least some data are available to read. Will try to receive.");
251 peer_socket->async_wait
252 (Peer_socket::wait_read, [logger_ptr, peer_socket,
253 target_payload_blob_func = std::move(target_payload_blob_func),
254 on_rcvd_or_error = std::move(on_rcvd_or_error),
255 should_interrupt_func = std::move(should_interrupt_func)]
258 on_wait_readable_or_error<true>
259 (logger_ptr, async_err_code, peer_socket, std::move(should_interrupt_func), std::move(on_rcvd_or_error),
260 std::move(target_payload_blob_func),
266template<
typename Task_err,
typename Should_
interrupt_func>
269 Should_interrupt_func&& should_interrupt_func, Task_err&& on_rcvd_or_error)
273 FLOW_LOG_SET_CONTEXT(logger_ptr, Log_component::S_TRANSPORT);
274 FLOW_LOG_TRACE(
"Starting: Connected local peer socket wants to read 1+ bytes to already-known location "
275 "TBD when at least some data are available to read. Will try to receive.");
277 auto on_rcvd_or_error_expected_form_func
278 = [on_rcvd_or_error = std::move(on_rcvd_or_error)]
282 on_rcvd_or_error(err_code);
285 peer_socket->async_wait
286 (Peer_socket::wait_read, [logger_ptr, peer_socket,
288 on_rcvd_or_error_expected_form_func = std::move(on_rcvd_or_error_expected_form_func),
289 should_interrupt_func = std::move(should_interrupt_func)]
292 on_wait_readable_or_error<false>
293 (logger_ptr, async_err_code, peer_socket, std::move(should_interrupt_func),
294 std::move(on_rcvd_or_error_expected_form_func),
303template<
typename Protocol>
309template<
typename Protocol>
315template<
typename Protocol>
321template<
typename Protocol>
327template<
typename Protocol>
330 using flow::util::ostream_op_string;
331 using std::length_error;
333 if (new_size_but_really_must_equal_current !=
size(proto))
335 throw length_error(ostream_op_string
336 (
"Opt_peer_process_credentials does not actually support resizing; requested size [",
337 new_size_but_really_must_equal_current,
"] differs from forever-size [",
338 size(proto),
"]. boost.asio internal bug or misuse?"));
Gettable (read-only) socket option for use with asio_local_stream_socket::Peer_socket ....
size_t size(const Protocol &proto) const
For internal boost.asio use, to enable Peer_socket::get_option(Opt_peer_process_credentials&) to work...
Opt_peer_process_credentials()
Default ctor: each value is initialized to zero or equivalent.
Opt_peer_process_credentials & operator=(const Opt_peer_process_credentials &src)
Methods.
int level(const Protocol &proto) const
For internal boost.asio use, to enable Peer_socket::get_option(Opt_peer_process_credentials&) to work...
Opt_peer_process_credentials(const Opt_peer_process_credentials &src)
Boring copy ctor.
void * data(const Protocol &proto)
For internal boost.asio use, to enable Peer_socket::get_option(Opt_peer_process_credentials&) to work...
int name(const Protocol &proto) const
For internal boost.asio use, to enable Peer_socket::get_option(Opt_peer_process_credentials&) to work...
void resize(const Protocol &proto, size_t new_size_but_really_must_equal_current) const
For internal boost.asio use, to enable Peer_socket::get_option(Opt_peer_process_credentials&) to work...
A process's credentials (PID, UID, GID as of this writing).
Additional (versus boost.asio) APIs for advanced work with local stream (Unix domain) sockets includi...
local_ns::stream_protocol Protocol
Short-hand for boost.asio Unix domain stream-socket protocol.
Protocol::socket Peer_socket
Short-hand for boost.asio Unix domain peer stream-socket (usually-connected-or-empty guy).
void on_wait_writable_or_error(flow::log::Logger *logger_ptr, const Error_code &sys_err_code, Native_handle payload_hndl, const util::Blob_const &payload_blob_ref, Peer_socket *peer_socket_ptr, Task_err &&on_sent_or_error)
Helper of async_write_with_native_handle() used as the callback executed when waiting for writability...
void async_write_with_native_handle(flow::log::Logger *logger_ptr, Peer_socket *peer_socket_ptr, Native_handle payload_hndl, const util::Blob_const &payload_blob, Task_err &&on_sent_or_error)
boost.asio extension similar to boost::asio::async_write(Peer_socket&, Blob_const,...
void async_read_with_target_func(flow::log::Logger *logger_ptr, Peer_socket *peer_socket, Target_payload_blob_func &&target_payload_blob_func, Should_interrupt_func &&should_interrupt_func, Task_err_blob &&on_rcvd_or_error)
boost.asio extension similar to boost::asio::async_read(Peer_socket&, Blob_mutable,...
void async_read_interruptible(flow::log::Logger *logger_ptr, Peer_socket *peer_socket, util::Blob_mutable target_payload_blob, Should_interrupt_func &&should_interrupt_func, Task_err &&on_rcvd_or_error)
boost.asio extension similar to boost::asio::async_read(Peer_socket&, Blob_mutable,...
const uint8_t * blob_data(const Blob_const &blob)
Syntactic-sugary helper that returns pointer to first byte in an immutable buffer,...
boost::asio::mutable_buffer Blob_mutable
Short-hand for an mutable blob somewhere in memory, stored as exactly a void* and a size_t.
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::Error_code Error_code
Short-hand for flow::Error_code which is very common.
A monolayer-thin wrapper around a native handle, a/k/a descriptor a/k/a FD.
bool null() const
Returns true if and only if m_native_handle equals S_NULL_HANDLE.