23#include <flow/common.hpp>
33static_assert(
false,
"Flow-IPC must define Opt_peer_process_credentials w/ Linux SO_PEERCRED semantics. "
34 "Build in Linux only.");
92 template<
typename Protocol>
109 template<
typename Protocol>
126 template<
typename Protocol>
143 template<
typename Protocol>
162 template<
typename Protocol>
163 void resize(
const Protocol& proto,
size_t new_size_but_really_must_equal_current)
const;
170template<
typename Task_err>
175 Task_err&& on_sent_or_error)
178 using flow::util::buffers_dump_string;
180 assert(peer_socket_ptr);
181 assert((!payload_hndl.
null()) && (payload_blob.size() != 0));
183 auto& peer_socket = *peer_socket_ptr;
185 FLOW_LOG_SET_CONTEXT(logger_ptr, Log_component::S_TRANSPORT);
187 FLOW_LOG_TRACE(
"Starting: Via connected local peer socket, will send handle [" << payload_hndl <<
"] with "
188 "blob of size [" << payload_blob.size() <<
"] "
189 "located @ [" << payload_blob.data() <<
"].");
192 FLOW_LOG_DATA(
"Starting: Blob contents are "
193 "[" << buffers_dump_string(payload_blob,
" ") <<
"].");
222 peer_socket.async_wait
223 (Peer_socket::wait_write,
224 [logger_ptr, payload_hndl, payload_blob, peer_socket_ptr,
225 on_sent_or_error = std::move(on_sent_or_error)]
229 std::move(on_sent_or_error));
233template<
typename Task_err_blob,
typename Target_payload_blob_func,
typename Should_
interrupt_func>
235 (flow::log::Logger* logger_ptr,
Peer_socket* peer_socket,
236 Target_payload_blob_func&& target_payload_blob_func, Should_interrupt_func&& should_interrupt_func,
237 Task_err_blob&& on_rcvd_or_error)
243 FLOW_LOG_SET_CONTEXT(logger_ptr, Log_component::S_TRANSPORT);
244 FLOW_LOG_TRACE(
"Starting: Connected local peer socket wants to read 1+ bytes to some currently-unknown location "
245 "TBD when at least some data are available to read. Will try to receive.");
252 peer_socket->async_wait
253 (Peer_socket::wait_read, [logger_ptr, peer_socket,
254 target_payload_blob_func = std::move(target_payload_blob_func),
255 on_rcvd_or_error = std::move(on_rcvd_or_error),
256 should_interrupt_func = std::move(should_interrupt_func)]
259 on_wait_readable_or_error<true>
260 (logger_ptr, async_err_code, peer_socket, std::move(should_interrupt_func), std::move(on_rcvd_or_error),
261 std::move(target_payload_blob_func),
267template<
typename Task_err,
typename Should_
interrupt_func>
270 Should_interrupt_func&& should_interrupt_func, Task_err&& on_rcvd_or_error)
274 FLOW_LOG_SET_CONTEXT(logger_ptr, Log_component::S_TRANSPORT);
275 FLOW_LOG_TRACE(
"Starting: Connected local peer socket wants to read 1+ bytes to already-known location "
276 "TBD when at least some data are available to read. Will try to receive.");
278 auto on_rcvd_or_error_expected_form_func
279 = [on_rcvd_or_error = std::move(on_rcvd_or_error)]
283 on_rcvd_or_error(err_code);
286 peer_socket->async_wait
287 (Peer_socket::wait_read, [logger_ptr, peer_socket,
289 on_rcvd_or_error_expected_form_func = std::move(on_rcvd_or_error_expected_form_func),
290 should_interrupt_func = std::move(should_interrupt_func)]
293 on_wait_readable_or_error<false>
294 (logger_ptr, async_err_code, peer_socket, std::move(should_interrupt_func),
295 std::move(on_rcvd_or_error_expected_form_func),
304template<
typename Protocol>
310template<
typename Protocol>
316template<
typename Protocol>
322template<
typename Protocol>
328template<
typename Protocol>
331 using flow::util::ostream_op_string;
332 using std::length_error;
334 if (new_size_but_really_must_equal_current !=
size(proto))
336 throw length_error(ostream_op_string
337 (
"Opt_peer_process_credentials does not actually support resizing; requested size [",
338 new_size_but_really_must_equal_current,
"] differs from forever-size [",
339 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)
Boring copy assignment.
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.