Flow-IPC 1.0.2
Flow-IPC project: Full implementation reference.
|
Internal, non-movable pImpl-lite implementation of Server_session_mv class template. More...
#include <server_session_impl.hpp>
Classes | |
struct | Open_channel_req |
An open-channel request out-message. More... | |
Public Member Functions | |
Server_session_impl (flow::log::Logger *logger_ptr, const Server_app &srv_app_ref, transport::sync_io::Native_socket_stream &&master_channel_sock_stm) | |
For use by internal user Session_server: See Server_session_mv counterpart. More... | |
~Server_session_impl () | |
See Server_session_mv counterpart. More... | |
template<typename Session_server_impl_t , typename Task_err , typename Cli_app_lookup_func , typename Cli_namespace_func , typename Pre_rsp_setup_func , typename N_init_channels_by_srv_req_func , typename Mdt_load_func > | |
void | async_accept_log_in (Session_server_impl_t *srv, Channels *init_channels_by_srv_req, Mdt_reader_ptr *mdt_from_cli_or_null, Channels *init_channels_by_cli_req, Cli_app_lookup_func &&cli_app_lookup_func, Cli_namespace_func &&cli_namespace_func, Pre_rsp_setup_func &&pre_rsp_setup_func, N_init_channels_by_srv_req_func &&n_init_channels_by_srv_req_func, Mdt_load_func &&mdt_load_func, Task_err &&on_done_func) |
For use by internal user Session_server: See Server_session_mv counterpart. More... | |
const Client_app * | client_app () const |
See Server_session_mv counterpart. More... | |
template<typename Task_err , typename On_passive_open_channel_handler > | |
bool | init_handlers (Task_err &&on_err_func_arg, On_passive_open_channel_handler &&on_passive_open_channel_func_arg) |
See Server_session_mv counterpart. More... | |
template<typename Task_err > | |
bool | init_handlers (Task_err &&on_err_func_arg) |
See Server_session_mv counterpart. More... | |
Mdt_builder_ptr | mdt_builder () |
See Server_session_mv counterpart. More... | |
bool | open_channel (Channel_obj *target_channel, const Mdt_builder_ptr &mdt, Error_code *err_code=0) |
See Server_session_mv counterpart. More... | |
bool | open_channel (Channel_obj *target_channel, Error_code *err_code=0) |
See Server_session_mv counterpart. More... | |
const Session_token & | session_token () const |
See Server_session_mv counterpart. More... | |
const Base & | base () const |
See Server_session_mv counterpart. More... | |
Public Member Functions inherited from ipc::session::Session_base< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload > | |
const Shared_name & | srv_namespace () const |
See Server_session_impl, Client_session_impl. More... | |
const Shared_name & | cli_namespace () const |
See Server_session_impl, Client_session_impl. More... | |
const Client_app * | cli_app_ptr () const |
See Server_session_impl, Client_session_impl. More... | |
Shared_name | cur_ns_store_mutex_absolute_name () const |
Computes the name of the interprocess named-mutex used to control reading/writing to the file storing (written by server, read by client) the value for srv_namespace(). More... | |
fs::path | cur_ns_store_absolute_path () const |
Computes the absolute path to file storing (written by server, read by client) the value for srv_namespace(). More... | |
Shared_name | session_master_socket_stream_acceptor_absolute_name () const |
Computes the absolute name at which the server shall set up a transport::Native_socket_stream_acceptor to which client shall transport::Native_socket_stream::sync_connect() in order to establish a PEER-state session. More... | |
Static Public Attributes | |
static constexpr schema::ShmType | S_SHM_TYPE = S_SHM_TYPE_OR_NONE |
See Session_mv counterpart. More... | |
static constexpr bool | S_SHM_ENABLED = S_SHM_TYPE != schema::ShmType::NONE |
See Session_mv counterpart. More... | |
static constexpr bool | S_MQS_ENABLED = Base::S_MQS_ENABLED |
See Server_session_mv counterpart. More... | |
static constexpr bool | S_SOCKET_STREAM_ENABLED = Base::S_SOCKET_STREAM_ENABLED |
See Server_session_mv counterpart. More... | |
static constexpr bool | S_GRACEFUL_FINISH_REQUIRED = S_GRACEFUL_FINISH_REQUIRED_V |
Short-hand for template parameter knob S_GRACEFUL_FINISH_REQUIRED_V : see class template doc header. More... | |
Static Public Attributes inherited from ipc::session::Session_base< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload > | |
static constexpr bool | S_MQS_ENABLED = S_MQ_TYPE_OR_NONE != schema::MqType::NONE |
See Session_mv. More... | |
static constexpr bool | S_SOCKET_STREAM_ENABLED = (!S_MQS_ENABLED) || S_TRANSMIT_NATIVE_HANDLES |
See Session_mv. More... | |
Protected Member Functions | |
template<typename Task > | |
void | sub_class_set_deinit_func (Task &&task) |
Utility for sub-classes: ensures that task() is invoked near the end of *this dtor's execution, from thread U, after thread W is joined, and any async_accept_log_in() on-done handler has fired with operation-aborted code. More... | |
flow::async::Single_thread_task_loop * | async_worker () |
Utility for sub-classes: provides ability to schedule or post tasks onto thread W. More... | |
Master_structured_channel * | master_channel () |
Utility for sub-classes: provides ability to do work on the session master channel after our async_accept_log_in() succeeds, but before the sub-classed wrapper of its on-done handler succeeds. More... | |
const Master_structured_channel & | master_channel_const () const |
Analogous to Client_session_impl::master_channel_const(). More... | |
void | dtor_async_worker_stop () |
Analogous to Client_session_impl::dtor_async_worker_stop(). See that doc header. More... | |
Protected Member Functions inherited from ipc::session::Session_base< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload > | |
Session_base (const Client_app &cli_app_ref, const Server_app &srv_app_ref, flow::async::Task_asio_err &&on_err_func, On_passive_open_channel_func &&on_passive_open_channel_func_or_empty_arg) | |
Constructs: Client_session_impl form (the user is the one constructing the object, though in NULL state). More... | |
Session_base (const Server_app &srv_app_ref) | |
Constructs: Server_session_impl form (Session_server is the one constructing the object, though in NULL state, before log-in has completed, but after the socket-stream connection has been established). More... | |
void | set_srv_namespace (Shared_name &&srv_namespace_new) |
Sets srv_namespace() (do not call if already set). More... | |
void | set_cli_namespace (Shared_name &&cli_namespace_new) |
Sets cli_namespace() (do not call if already set). More... | |
void | set_cli_app_ptr (const Client_app *cli_app_ptr_new) |
Sets cli_app_ptr() (do not call if already set). More... | |
void | set_on_passive_open_channel_func (On_passive_open_channel_func &&on_passive_open_channel_func) |
Sets on_passive_open_channel_func_or_empty() (do not call if already set; do not call if user intends for passive-opens to be disabled on this side). More... | |
void | set_on_err_func (flow::async::Task_asio_err &&on_err_func_arg) |
Sets on_err_func() (do not call if already set). More... | |
bool | on_err_func_set () const |
Returns true if and only if set_on_err_func() has been called. More... | |
const On_passive_open_channel_func & | on_passive_open_channel_func_or_empty () const |
The on-passive-open handler (may be empty even in final state, meaning user wants passive-opens disabled on this side). More... | |
void | hose (const Error_code &err_code) |
Marks this session as hosed for (truthy) reason err_code ; and synchronously invokes on-error handler; only invoke if not already hosed(). More... | |
bool | hosed () const |
Returns true if and only if hose() has been called. More... | |
Private Types | |
using | Persistent_mq_handle_from_cfg = typename Base::Persistent_mq_handle_from_cfg |
See Session_base. More... | |
using | On_passive_open_channel_func = typename Base::On_passive_open_channel_func |
See Session_base. More... | |
using | Master_structured_channel_ptr = typename Base::Master_structured_channel_ptr |
See Session_base. More... | |
using | Open_channel_req_ptr = boost::shared_ptr< Open_channel_req > |
Short-hand for ref-counted pointer to Open_channel_req. More... | |
Private Member Functions | |
bool | init_handlers_impl (flow::async::Task_asio_err &&on_err_func_arg, On_passive_open_channel_func &&on_passive_open_channel_func_or_empty_arg) |
Core of both init_handlers() overloads, to be invoked in thread W. More... | |
bool | handlers_are_set () const |
In thread W, returns whether init_handlers_impl() has yet executed. More... | |
void | on_master_channel_error (const Error_code &err_code) |
In thread W, handler for m_master_channel indicating incoming-direction channel-hosing error. More... | |
void | on_master_channel_open_channel_req (typename Master_structured_channel::Msg_in_ptr &&open_channel_req) |
In thread W, handler for m_master_channel receiving a passive-open (a/k/a open-channel-to-server) request. More... | |
bool | create_channel_and_resources (Shared_name *mq_name_c2s_or_none_ptr, Shared_name *mq_name_s2c_or_none_ptr, util::Native_handle *remote_hndl_or_null_ptr, Channel_obj *opened_channel_ptr, bool active_else_passive) |
In thread W acquires the needed shared sources (MQs and/or Native_handle pair as of this writing) and creates local Channel_obj to emit to the user thus completing the channel-open on this side. More... | |
bool | make_channel_mqs (Persistent_mq_handle_from_cfg *mq_c2s, Persistent_mq_handle_from_cfg *mq_s2c, Shared_name *mq_name_c2s, Shared_name *mq_name_s2c, Error_code *err_code) |
Helper for create_channel_and_resources(), invoked and compiled if and only if S_MQS_ENABLED, that creates the underlying client->server and server->client MQs and local handles thereto, and outputs these things via out-args. More... | |
Private Attributes | |
transport::Protocol_negotiator | m_protocol_negotiator |
Handles the protocol negotiation at the start of the pipe, as pertains to algorithms perpetuated by the vanilla ipc::session Session hierarchy. More... | |
transport::Protocol_negotiator | m_protocol_negotiator_aux |
Analogous to m_protocol_negotiator but pertains to algorithms perpetuated by (if relevant) non-vanilla ipc::session Session hierarchy implemented on top of our vanilla ipc::session Session hierarchy. More... | |
flow::async::Task_asio_err | m_log_in_on_done_func |
The on_done_func argument to async_accept_log_in(); .empty() except while the (at most one, ever) async_accept_log_in() is outstanding. More... | |
transport::sync_io::Native_socket_stream | m_master_sock_stm |
The pre-connected (PEER-state) socket stream peer; is non-as-if-default-cted only up to async_accept_log_in(), at which point it is moved-to m_master_channel. More... | |
Error_code | m_pre_init_err_code |
Unused/falsy except when in almost-PEER state (past successful async_accept_log_in(), before init_handlers() invoked by user), and m_master_channel reports incoming-direction error. More... | |
unsigned int | m_last_passively_opened_channel_id |
Identical to Client_session_impl::m_last_passively_opened_channel_id. More... | |
unsigned int | m_last_actively_opened_channel_id |
Identical to Client_session_impl::m_last_actively_opened_channel_id. More... | |
unsigned int | m_last_channel_mq_id |
Unique component of MQ names generated by make_channel_mqs() (if relevant; else untouched). More... | |
flow::async::Single_thread_task_loop | m_async_worker |
Worker thread (a/k/a thread W). More... | |
Master_structured_channel_ptr | m_master_channel |
The session master channel. More... | |
Function< void()> | m_deinit_func_or_empty |
See sub_class_set_deinit_func(). .empty() unless that was called at least once. More... | |
std::optional< typename Base::Graceful_finisher > | m_graceful_finisher |
Null until PEER state is reached, and NULL unless compile-time S_GRACEFUL_FINISH_REQUIRED is true , this is used to block at the start of dtor to synchronize with the opposing Session dtor for safety. More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<schema::MqType S_MQ_TYPE_OR_NONE, bool S_TRANSMIT_NATIVE_HANDLES, typename Mdt_payload , schema::ShmType S_SHM_TYPE_OR_NONE, size_t S_SHM_MAX_HNDL_SZ, bool S_GRACEFUL_FINISH_REQUIRED_V> | |
std::ostream & | operator<< (std::ostream &os, const Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V > &val) |
Prints string representation of the given Server_session_impl to the given ostream . More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from ipc::session::Session_base< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload > | |
static Structured_msg_builder_config | heap_fixed_builder_config (flow::log::Logger *logger_ptr) |
See Session_mv::heap_fixed_builder_config() (1-arg). More... | |
static Structured_msg_reader_config | heap_reader_config (flow::log::Logger *logger_ptr) |
See Session_mv::heap_reader_config() (1-arg). More... | |
Public Attributes inherited from ipc::session::Session_base< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload > | |
const Server_app & | m_srv_app_ref |
Reference to Server_app (referring to local process in Server_session_impl, opposing process in Client_session_impl). More... | |
Static Protected Attributes inherited from ipc::session::Session_base< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload > | |
static constexpr util::Fine_duration | S_OPEN_CHANNEL_TIMEOUT = boost::chrono::seconds(60) |
Internal timeout for open_channel() . More... | |
static constexpr size_t | S_MQS_MAX_MSG_SZ = 8 * 1024 |
The max sendable MQ message size as decided by Server_session_impl::make_channel_mqs() (and imposed on both sides, both directions), if S_MQS_ENABLED and Server_session_impl::S_SHM_ENABLED is false , when a channel is opened (regardless of which side did the active-open or requested pre-opening at session start). More... | |
Internal, non-movable pImpl-lite implementation of Server_session_mv class template.
In and of itself it would have been directly and publicly usable; however Server_session_mv adds move semantics.
protected
, to be exposed public
ly by Server_session_dtl) API is in Server_session_mv doc header; that class template forwards to this one. All discussion of pImpl-lite-related notions is also there. See that doc header first please. Then come back here.Generally, I (ygoldfel) recommend looking through and understanding Client_session_impl first. It is similar but somewhat more complex, and once it is understood, you'll be able to understand Server_session_impl easily. Plus its logic is complementary to a *this
, as the two directly interoperate via a couple of IPC forms. The below discussion does assume one has read/understood Client_session_impl doc header.
Thread U represents all threads other than thread W: since the relevant methods are to be called by the user sans concurrency, those threads as a collection can be thought of as one thread.
Thread W is the async worker thread where most work is done; this helps us entirely avoid mutexes. async_accept_log_in() is called exactly once, internally by Session_server; and subsequently open_channel() is fairly infrequently called. So it's not necessary to avoid latency by doing work concurrently in threads U and W. So we keep it simple by posting most stuff onto thread W.
The state machine of Server_session_impl is simpler than Client_session_impl. The asymmetry is, firstly, due to the client-server setup: Session_server is the one, on the server end, that awaits the initial transport::Native_socket_stream connection. Once a PEER-state Native_socket_stream
is ready, only then does Session_server create a Server_session_dtl (which is a public
facade to Server_session_mv, which is a movable unique_ptr
wrapper around this Server_session_impl). So *this
, unlike a Client_session_impl, does not need to connect a socket. Next, Server_session_impl just needs to complete one async step, which is in practice immediately (and, by contract, only once) invoked: async_accept_log_in(). At this stage user does not have the Server_session_mv yet, so we're still in internal-code land. (By contrast Client_session is created directly by the user and is immediately publicly available as a stand-alone object.) async_accept_log_in() immediately upgrades the Native_socket_stream
to a transport::Channel and then immediately upgrades that to a transport::struc::Channel, saving it to m_master_channel (all synchronously). Lastly is the actual async work: awaiting the log-in request from Client_session. Once that is received, we respond via m_master_channel, either with log-in success or failure. Assuming success, we invoke the (internal) async_accept_log_in() handler; on failure same thing but with a failure Error_code.
Update (init-channels feature has been added): The preceding paragraph holds fully if and only if:
LogInReq
) requested 0 init-channels to be opened on its behalf; andHowever, if the sum of these 2 numbers (as determined upon successful receipt on LogInReq
, and assuming everything else was also successful, up-to-and-including sending successful LogInRsp
) is N=1+, then before async_accept_log_in() can reach almost-PEER state (and fire completion handler), there is 1 more async-step:
LogInRsp
as explained);OpenChannelToClientReq
messages with names/handles for each of the N init-channels (exactly as would occur on N open_channel() calls in PEER state);OpenChannelToClientRsp
response, indicating the last of the N channels has been accepted, and client is now in PEER state and ready for passive-opens (i.e., we can enter PEER-state which enabled open_channel() by the local user).Why this last async step? Couldn't we just do the send()
s and go to almost-PEER state immediately? Almost: but if we did that, then if the user immediately issued init_handlers() and an open_channel(), then the opposing Client_session_impl might not, technically, be quick enough to have moved to its own PEER state; then its OpenChannelToClientReq
handler from the pre-PEER state (CONNECTING state) might be triggered; this would cause... nothing good. However the ACK from Client_session_impl is sent only just before entering PEER state, at which point it is safe for us to issue open_channel()s.
Our async_accept_log_in() is analogous/complementary to Client_session_impl::async_connect(), but the diff is that the user only gets access to a *this
upon success of this async op; and never gets access upon failure at all. So that's another source of asymmetry versus Client_session_impl. Thus:
*this
, once *this
is in (almost-)PEER state.)Therefore there's no need to track an m_state
the way Client_session_impl does. If m_log_in_on_done_func is non-empty, then async_accept_log_in() is outstanding (analogous to Client_session_impl CONNECTING state). Otherwise see the "almost-PEER" section just below.
There is a minor wrinkle in Server_session_mv (and thus Server_session_impl). Once the user obtains the Server_session_mv, it is in the so-called almost-PEER state. That is because it needs 1-2 more pieces of info to be set before it is formally in PEER state as specified by Session concept. Namely its on-error handler must be set (mandatory), as must its on-passive-open handler (optional; in that leaving it unspecified is allowed and means passive-opens are disabled on this side). To do so the user shall call init_handlers(). Until this is done, open_channel() and other public PEER-state APIs shall no-op and return sentinel/false
.
There is a subtlety in how this are-handlers-set check is performed. The crux of it is that m_master_channel can report an error at any time starting with async_accept_log_in() (where it is first created), and what to do is quite different in each case:
Because the m_master_channel error handler is relevant across all of the above, and it is executed in thread W for reasons explained above (avoiding mutexes, etc.), to avoid concurrency difficulties the are-handlers-set check, and the assignment of the handlers, is also done in thread W. Hence, like most code in Server_session_impl, init_handlers() posts all its work onto thread W. All public APIs, even simple ones like session_token(), do the same, and that thread-W work always begins by ensuring handlers_are_set().
Once PEER state is achieved, to the user *this
is (just like Client_session_impl) an impl of Session concept. Internally it's somewhat different.
Here our algorithm is complementary to the PEER state algorithm in Client_session_impl. Namely we expect passive-opens via an appropriate transport::struc::Channel::expect_msgs(); and we allow active-opens via open_channel(). The details of how these work is best understood just by reading that code inline. All in all, publicly it's just like Client_session_impl; but internally it is its complement and in fact has different (complementary) responsibilities. Most notably, regarding active-opens and passive-opens:
Native_handle
) shall be sent-over, via m_master_channel, to the Client_session_impl.Client_session_impl active-opens and passive-opens act in a complementary fashion, never acquiring these resources but knowing what to expect.
Otherwise open_channel() is set up similarly to Client_session_impl::open_channel(), namely the non-blocking/synchronous facade with async-with-timeout internals. See Client_session_impl doc header for brief discussion.
S_MQ_TYPE_OR_NONE | See Server_session counterpart. |
S_TRANSMIT_NATIVE_HANDLES | See Server_session counterpart. |
Mdt_payload | See Server_session counterpart. |
S_SHM_TYPE_OR_NONE | See common.capnp ShmType capnp-enum definition. |
S_SHM_MAX_HNDL_SZ | Ignored if S_SHM_TYPE_OR_NONE indicates we are not SHM-enabled, this otherwise indicates the max size of a SHM handle's blob serialization. If ignored it must be set to 0 (convention). |
S_GRACEFUL_FINISH_REQUIRED_V | true if and only if Session_base::Graceful_finisher must be used. See its doc header for explanation when that would be the case. |
Definition at line 185 of file server_session_impl.hpp.
using ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::Base = Session_base<S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload> |
Short-hand for base type.
Definition at line 193 of file server_session_impl.hpp.
using ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::Channel_obj = typename Base::Channel_obj |
See Server_session_mv counterpart.
Definition at line 199 of file server_session_impl.hpp.
using ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::Channels = typename Base::Channels |
See Session_mv counterpart.
Definition at line 202 of file server_session_impl.hpp.
|
protected |
See Session_base.
Definition at line 376 of file server_session_impl.hpp.
|
private |
See Session_base.
Definition at line 441 of file server_session_impl.hpp.
using ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::Mdt_builder = typename Base::Mdt_builder |
See Server_session_mv counterpart.
Definition at line 211 of file server_session_impl.hpp.
using ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::Mdt_builder_ptr = typename Base::Mdt_builder_ptr |
See Server_session_mv counterpart.
Definition at line 214 of file server_session_impl.hpp.
using ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::Mdt_payload_obj = typename Base::Mdt_payload_obj |
See Server_session_mv counterpart.
Definition at line 205 of file server_session_impl.hpp.
using ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::Mdt_reader_ptr = typename Base::Mdt_reader_ptr |
See Server_session_mv counterpart.
Definition at line 208 of file server_session_impl.hpp.
|
private |
See Session_base.
Definition at line 438 of file server_session_impl.hpp.
|
private |
Short-hand for ref-counted pointer to Open_channel_req.
shared_ptr
as returned by us. Definition at line 472 of file server_session_impl.hpp.
|
private |
See Session_base.
Definition at line 435 of file server_session_impl.hpp.
using ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::Session_base_obj = Base |
Short-hand for Session_base super-class.
Definition at line 196 of file server_session_impl.hpp.
using ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::Structured_msg_builder_config = typename Base::Structured_msg_builder_config |
See Session_mv counterpart.
Definition at line 217 of file server_session_impl.hpp.
using ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::Structured_msg_reader_config = typename Base::Structured_msg_reader_config |
See Session_mv counterpart.
Definition at line 220 of file server_session_impl.hpp.
|
explicit |
For use by internal user Session_server: See Server_session_mv counterpart.
logger_ptr | See Server_session_mv counterpart. |
srv_app_ref | See Server_session_mv counterpart. |
master_channel_sock_stm | See Server_session_mv counterpart. |
Definition at line 681 of file server_session_impl.hpp.
References ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::m_async_worker, and ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::m_master_sock_stm.
ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::~Server_session_impl |
See Server_session_mv counterpart.
Definition at line 784 of file server_session_impl.hpp.
References ipc::session::error::S_OBJECT_SHUTDOWN_ABORTED_COMPLETION_HANDLER.
void ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::async_accept_log_in | ( | Session_server_impl_t * | srv, |
Channels * | init_channels_by_srv_req, | ||
Mdt_reader_ptr * | mdt_from_cli_or_null, | ||
Channels * | init_channels_by_cli_req, | ||
Cli_app_lookup_func && | cli_app_lookup_func, | ||
Cli_namespace_func && | cli_namespace_func, | ||
Pre_rsp_setup_func && | pre_rsp_setup_func, | ||
N_init_channels_by_srv_req_func && | n_init_channels_by_srv_req_func, | ||
Mdt_load_func && | mdt_load_func, | ||
Task_err && | on_done_func | ||
) |
For use by internal user Session_server: See Server_session_mv counterpart.
srv | See Server_session_mv counterpart. |
init_channels_by_srv_req | See Server_session_mv counterpart. |
mdt_from_cli_or_null | See Server_session_mv counterpart. |
init_channels_by_cli_req | See Server_session_mv counterpart. |
cli_app_lookup_func | See Server_session_mv counterpart. |
cli_namespace_func | See Server_session_mv counterpart. |
pre_rsp_setup_func | See Server_session_mv counterpart. |
n_init_channels_by_srv_req_func | See Server_session_mv counterpart. |
mdt_load_func | See Server_session_mv counterpart. |
on_done_func | See Server_session_mv counterpart. |
Definition at line 1582 of file server_session_impl.hpp.
References ipc::transport::Socket_stream_channel< SIO >::remote_peer_process_credentials(), ipc::session::error::S_INVALID_ARGUMENT, ipc::transport::struc::Channel_base::S_SERIALIZE_VIA_HEAP, ipc::session::error::S_SERVER_MASTER_LOG_IN_REQUEST_CLIENT_APP_DISALLOWED_OR_UNKNOWN, ipc::session::error::S_SERVER_MASTER_LOG_IN_REQUEST_CLIENT_APP_INCONSISTENT_CREDS, ipc::session::error::S_SERVER_MASTER_LOG_IN_REQUEST_CONFIG_MISMATCH, ipc::session::error::S_SESSION_OPEN_CHANNEL_SERVER_CANNOT_PROCEED_RESOURCE_UNAVAILABLE, and ipc::util::Shared_name::str().
|
protected |
Utility for sub-classes: provides ability to schedule or post tasks onto thread W.
Definition at line 2189 of file server_session_impl.hpp.
const Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::Base & ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::base |
See Server_session_mv counterpart.
Definition at line 2176 of file server_session_impl.hpp.
const Client_app * ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::client_app |
See Server_session_mv counterpart.
Definition at line 829 of file server_session_impl.hpp.
|
private |
In thread W acquires the needed shared sources (MQs and/or Native_handle
pair as of this writing) and creates local Channel_obj to emit to the user thus completing the channel-open on this side.
If active-open on our part, we do this immediately in mdt_builder() – before open_channel() even – but before the Channel_obj can be emitted to the user (1) open_channel() must actually be called (obv) and (2) client must respond OK to our open-channel-to-client request out-message. If passive-open, we do this upon receiving client's open-channel-to-server request, before replying with our OK. Either way we are the ones acquiring the resources, then we send names/refs to those resources to client.
Returns false
if and only if could not acquire resources.
mq_name_c2s_or_none_ptr | If S_MQS_ENABLED this out-arg is the (non-empty) name of the client->server unidirectional MQ for the channel. Else ignored. Must be empty at entry or behavior undefined (assertion may trip). |
mq_name_s2c_or_none_ptr | Like the preceding but opposite-direction (server->client). |
remote_hndl_or_null_ptr | If S_SOCKET_STREAM_ENABLED this out-arg is the pre-connected Native_handle to send to the other side; we keep the other end and shove it into the Channel_obj out-arg. Else ignored. Must be .null() or behavior undefined (assertion may trip). |
opened_channel_ptr | Target Channel_obj we shall try to move-to PEER state. It'll be left unmodified if we return false . |
active_else_passive | true if this is from open_channel(); false if from on_master_channel_open_channel_req(). |
true
on success; false
if a resource could not be acquired. Definition at line 1352 of file server_session_impl.hpp.
|
protected |
Analogous to Client_session_impl::dtor_async_worker_stop(). See that doc header.
Definition at line 708 of file server_session_impl.hpp.
|
private |
In thread W, returns whether init_handlers_impl() has yet executed.
This shall be checked in the thread-W body of ~all APIs in this class.
Definition at line 945 of file server_session_impl.hpp.
bool ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::init_handlers | ( | Task_err && | on_err_func_arg | ) |
See Server_session_mv counterpart.
on_err_func_arg | See Server_session_mv counterpart. |
Definition at line 857 of file server_session_impl.hpp.
bool ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::init_handlers | ( | Task_err && | on_err_func_arg, |
On_passive_open_channel_handler && | on_passive_open_channel_func_arg | ||
) |
See Server_session_mv counterpart.
on_err_func_arg | See Server_session_mv counterpart. |
on_passive_open_channel_func_arg | See Server_session_mv counterpart. |
Definition at line 837 of file server_session_impl.hpp.
|
private |
Core of both init_handlers() overloads, to be invoked in thread W.
on_err_func_arg | See init_handlers(). Concretely-typed version of that arg. |
on_passive_open_channel_func_or_empty_arg | See init_handlers(). Concretely-typed version of that arg; or .empty() one if the passive-opens-disabled overload was called. |
Definition at line 875 of file server_session_impl.hpp.
|
private |
Helper for create_channel_and_resources(), invoked and compiled if and only if S_MQS_ENABLED, that creates the underlying client->server and server->client MQs and local handles thereto, and outputs these things via out-args.
On failure undoes everything it was able to do and returns false
; else returns true
.
mq_c2s | On success this is the handle to newly creates client->server unidirectional MQ for the new channel. |
mq_s2c | Like the preceding but opposite-direction (server->client). |
mq_name_c2s | Name for mq_c2s . |
mq_name_s2c | Name for mq_s2c . |
err_code | If false returned, this is the (truthy) reason code. |
true
on success; false
on failure. Definition at line 1485 of file server_session_impl.hpp.
References ipc::session::build_conventional_shared_name(), ipc::util::CREATE_ONLY, ipc::util::Shared_name::ct(), and ipc::util::shared_resource_permissions().
|
protected |
Utility for sub-classes: provides ability to do work on the session master channel after our async_accept_log_in() succeeds, but before the sub-classed wrapper of its on-done handler succeeds.
This is pushing my (ygoldfel) (and from coding guide) suggestion to avoid unrestricted protected
access to data members. It still "feels" okay but.... Hmmm.
Definition at line 2195 of file server_session_impl.hpp.
|
protected |
Analogous to Client_session_impl::master_channel_const().
See that doc header.
Definition at line 2201 of file server_session_impl.hpp.
Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::Mdt_builder_ptr ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::mdt_builder |
See Server_session_mv counterpart.
Definition at line 985 of file server_session_impl.hpp.
References ipc::util::Shared_name::str().
|
private |
In thread W, handler for m_master_channel indicating incoming-direction channel-hosing error.
It is possible that m_master_channel has been .reset()
in the meantime, by seeing log-in failure in on_master_channel_open_channel_req(), and no longer exists.
err_code | The non-success Error_code from transport::struc::Channel. |
Definition at line 2109 of file server_session_impl.hpp.
|
private |
In thread W, handler for m_master_channel receiving a passive-open (a/k/a open-channel-to-server) request.
If there is no issue with this request, and we're able to sync-send the open-channel response to that effect, this shall fire on-passive-open handler, giving it a new Channel_obj in PEER state + metadata. If there is a problem, then it's not a session-hosing situation; local user is none-the-wiser; except that if the send()
reveals a new error, then it is a session-hosing situation, and local user is informed via on-error handler.
open_channel_req | The request in-message from transport::struc::Channel. |
Definition at line 1243 of file server_session_impl.hpp.
References ipc::util::Shared_name::empty(), and ipc::util::Shared_name::str().
bool ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::open_channel | ( | Channel_obj * | target_channel, |
const Mdt_builder_ptr & | mdt, | ||
Error_code * | err_code = 0 |
||
) |
See Server_session_mv counterpart.
target_channel | See Server_session_mv counterpart. |
mdt | See Server_session_mv counterpart. |
err_code | See Server_session_mv counterpart. |
Definition at line 1074 of file server_session_impl.hpp.
References ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::open_channel(), ipc::session::error::S_SESSION_OPEN_CHANNEL_ACTIVE_TIMEOUT, ipc::session::error::S_SESSION_OPEN_CHANNEL_REMOTE_PEER_REJECTED_PASSIVE_OPEN, ipc::session::error::S_SESSION_OPEN_CHANNEL_SERVER_CANNOT_PROCEED_RESOURCE_UNAVAILABLE, and ipc::transport::error::S_TIMEOUT.
bool ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::open_channel | ( | Channel_obj * | target_channel, |
Error_code * | err_code = 0 |
||
) |
See Server_session_mv counterpart.
target_channel | See Server_session_mv counterpart. |
err_code | See Server_session_mv counterpart. |
Definition at line 1236 of file server_session_impl.hpp.
const Session_token & ipc::session::Server_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_SHM_MAX_HNDL_SZ, S_GRACEFUL_FINISH_REQUIRED_V >::session_token |
See Server_session_mv counterpart.
Definition at line 951 of file server_session_impl.hpp.
References ipc::transport::struc::NULL_SESSION_TOKEN.
|
protected |
Utility for sub-classes: ensures that task()
is invoked near the end of *this
dtor's execution, from thread U, after thread W is joined, and any async_accept_log_in() on-done handler has fired with operation-aborted code.
It requires being invoked from thread W. (Behavior is undefined otherwise; assertion may trip.)
The value it adds: A long story best told by specific example. See the original use case which is in shm::classic::Server_session_impl::async_accept_log_in(); it sets up certain SHM cleanup steps to occur, when the session ends.
As of this writing this can be invoked 2+ times if desired, but really the spirit of it is to either never call it, or call it exactly once during a certain stage of async_accept_log_in()'s async portion.
At the time task()
runs, the calling instance of the sub-class has been destroyed – thus it is, e.g., usually wrong to capture your this
in the task
lambda, except for logging. get_logger()
and get_log_component()
(which are immutable state) are still okay to use.
Task | Function object invoked as void with no args. |
task | task() shall execute before dtor returns. |
Definition at line 2183 of file server_session_impl.hpp.
|
related |
Prints string representation of the given Server_session_impl
to the given ostream
.
os | Stream to which to write. |
val | Object to serialize. |
os
. Definition at line 2207 of file server_session_impl.hpp.
|
mutableprivate |
Worker thread (a/k/a thread W).
Ordering: Should be declared before m_master_channel: It should destruct before the Task_engine
onto which its queued-up handlers might post()
items destructs prematurely.
mutable
?Well, session_token() is const
to the user but must .post()
which is non-const
. This fits the spirit of mutable
. I (ygoldfel) think.
Definition at line 643 of file server_session_impl.hpp.
|
private |
See sub_class_set_deinit_func(). .empty()
unless that was called at least once.
Definition at line 656 of file server_session_impl.hpp.
|
private |
Null until PEER state is reached, and NULL unless compile-time S_GRACEFUL_FINISH_REQUIRED is true
, this is used to block at the start of dtor to synchronize with the opposing Session
dtor for safety.
Definition at line 664 of file server_session_impl.hpp.
|
private |
Identical to Client_session_impl::m_last_actively_opened_channel_id.
Definition at line 623 of file server_session_impl.hpp.
|
private |
Unique component of MQ names generated by make_channel_mqs() (if relevant; else untouched).
The mechanic of assigning this (1, 2, ...) is same as m_last_passively_opened_channel_id. Note, though, this guy is very much not merely for logging: MQs must have unique names which are transmitted to the other side during the channel-open procedure.
Definition at line 631 of file server_session_impl.hpp.
|
private |
Identical to Client_session_impl::m_last_passively_opened_channel_id.
Definition at line 620 of file server_session_impl.hpp.
|
private |
The on_done_func
argument to async_accept_log_in(); .empty()
except while the (at most one, ever) async_accept_log_in() is outstanding.
In other words it is assigned at entry at async_accept_log_in() and .clear()
ed upon being invoked, indicating either success or failure of the log-in. Reminder: async_accept_log_in() may not be re-attempted.
It may be invoked by dtor, if it does not fire before dtor.
Definition at line 604 of file server_session_impl.hpp.
|
private |
The session master channel.
Accessed in thread W only (not protected by mutex).
Definition at line 653 of file server_session_impl.hpp.
|
private |
The pre-connected (PEER-state) socket stream peer; is non-as-if-default-cted only up to async_accept_log_in(), at which point it is moved-to m_master_channel.
Accessed only the one time, in async_accept_log_in(), and immediately emptied there. As of this writing that's in thread W, but that does not matter much.
Definition at line 611 of file server_session_impl.hpp.
|
private |
Unused/falsy except when in almost-PEER state (past successful async_accept_log_in(), before init_handlers() invoked by user), and m_master_channel reports incoming-direction error.
See class doc header for background.
Definition at line 617 of file server_session_impl.hpp.
|
private |
Handles the protocol negotiation at the start of the pipe, as pertains to algorithms perpetuated by the vanilla ipc::session Session
hierarchy.
Outgoing-direction state is touched when assembling LogInReq
to send to opposing Server_session
. Incoming-direction state is touched/verified at the start of interpreting LogInRsp
receiver from there.
Definition at line 584 of file server_session_impl.hpp.
|
private |
Analogous to m_protocol_negotiator but pertains to algorithms perpetuated by (if relevant) non-vanilla ipc::session Session
hierarchy implemented on top of our vanilla ipc::session Session
hierarchy.
For example, ipc::session::shm hierarchies can use this to version whatever additional protocol is required to establish SHM things.
Definition at line 594 of file server_session_impl.hpp.
|
staticconstexpr |
Short-hand for template parameter knob S_GRACEFUL_FINISH_REQUIRED_V
: see class template doc header.
Definition at line 243 of file server_session_impl.hpp.
|
staticconstexpr |
See Server_session_mv counterpart.
Definition at line 237 of file server_session_impl.hpp.
|
staticconstexpr |
See Session_mv counterpart.
Definition at line 231 of file server_session_impl.hpp.
|
staticconstexpr |
See Session_mv counterpart.
Definition at line 228 of file server_session_impl.hpp.
|
staticconstexpr |
See Server_session_mv counterpart.
Definition at line 240 of file server_session_impl.hpp.