dxd - dynax driver framework 2.7.0d222
cross platform open source driver development framework
Loading...
Searching...
No Matches
dx::pipe< rcv_t > Class Template Reference

pipe - Windows named pipes A dx::pipe is a bidirection, multi-client, multi-threaded communication channel between a pipe client and a pipe server. Both pipe sides feature a dedicated read thread to receive data from the opposite side notifiying installable listener std::functions. On the service side, a pipe server is instantiated for each pipe client connection. Until a new client connects, the pipe::server::instance remains waiting in pipe::server::instance::connect within its dedicated pipe read thread. If a client disconnects the pipe::server::instance terminates its read thread and is joined and released by the next pipe::server::run() or pipe::server::stop(). The pipe::server::instance super class can be template-parameterized to allow mimicking user client behaviour. Windows arbitrarily serializes operations on synchronous pipe handles, limiting it's named pipe concurrent synchronous operation capabilities to exactly one synchronous pipe per process (i.e. exactly one per process), effectively forcing both the pipe::server and the pipe client to be implemented using asynchronous OVERLAPPED I/O — introducing a whole host of unnecessary pitfalls and awkward behaviors. However, the MSDN documentation here apparently describes a different piece of software. Though dx::pipes can be used for any communication between user space software its purpose is to allow Windows service communication. A service itself runs with elevated privileges, whereas the clients typically run in the normal user context. Therefore, the pipe servers have defined their default ACLs for non-privileged access. More...

#include <dx_pipe.h>

Inheritance diagram for dx::pipe< rcv_t >:
Collaboration diagram for dx::pipe< rcv_t >:

Classes

struct  access
class  server
 server - accepts multiple concurrent pipe client connections Each accepted connection is served by its own pipe::server::instance, running on a dedicated read thread. run() keeps exactly one instance listening for the next client at all times: once ConnectNamedPipe() accepts a connection, that instance's own thread calls server::run() again - reaping already-concluded instances and spawning the next listener - before servicing its own connection. A concluded instance (client disconnected) therefore joins only at the start of the next run(), on a different thread: a std::jthread cannot join itself, so reaping cannot happen from within the concluding instance's own read thread. An otherwise idle server thus keeps its most recently used instance around until either the next connection or stop(), which unconditionally joins every instance - connected or not - synchronously before returning. More...
class  status

Public Member Functions

 dx_catchall_rethrow () virtual void free() noexcept
 operator const os_event () const noexcept
 operator os_event () noexcept
 operator::HANDLE () const noexcept

Protected Member Functions

 dx_catchall_rethrow (, "%s: handle:%llx access:%x:%x:%x:%x", id.c_str(), handle, access[0], access[1], access[2], access[3]) void free() noexcept override
template<typename snd_t>
const snd_t & operator<< (const snd_t &snd)
 pipe (const std::string &id, decltype(listen)::listeners &&listeners={}, const ::DWORD(&access)[4]=access::dflt)
virtual void read (std::stop_token stop_token) noexcept try
void run () try
::ULONG session () const
template<typename rcv_t>
dx::pipe::status promoted this (const os_result &value)
 ~pipe () override

Protected Attributes

::DWORD access [4] {}
shared::event attach {id}
overlapped connect
dx::pipe::status ERROR_PIPE_BUSY
::HANDLE handle = invalid_t
std::string id
overlapped in
dx_catchall(, "%s: handle:%llx", id.c_str(), handle) public listen< std::function< void(const rcv_t &)> > listen
overlapped out
bool overlapped {}
::HANDLE process = ::GetCurrentProcess()
event< userread_thread_started {}
std::stop_callback< std::function< void()> > stop_callback {this->get_stop_token(), [this](){this->free();}}
class dx::pipe::server this

Detailed Description

template<typename rcv_t>
class dx::pipe< rcv_t >

pipe - Windows named pipes A dx::pipe is a bidirection, multi-client, multi-threaded communication channel between a pipe client and a pipe server. Both pipe sides feature a dedicated read thread to receive data from the opposite side notifiying installable listener std::functions. On the service side, a pipe server is instantiated for each pipe client connection. Until a new client connects, the pipe::server::instance remains waiting in pipe::server::instance::connect within its dedicated pipe read thread. If a client disconnects the pipe::server::instance terminates its read thread and is joined and released by the next pipe::server::run() or pipe::server::stop(). The pipe::server::instance super class can be template-parameterized to allow mimicking user client behaviour. Windows arbitrarily serializes operations on synchronous pipe handles, limiting it's named pipe concurrent synchronous operation capabilities to exactly one synchronous pipe per process (i.e. exactly one per process), effectively forcing both the pipe::server and the pipe client to be implemented using asynchronous OVERLAPPED I/O — introducing a whole host of unnecessary pitfalls and awkward behaviors. However, the MSDN documentation here apparently describes a different piece of software. Though dx::pipes can be used for any communication between user space software its purpose is to allow Windows service communication. A service itself runs with elevated privileges, whereas the clients typically run in the normal user context. Therefore, the pipe servers have defined their default ACLs for non-privileged access.

Each of the following states covers a distinct scope; none is derivable from another: handle no pipe open status last OS result; drives connection and requests the read thread's stop on connection loss connection connected/disconnected, awaitable by users of the pipe attach cross-process: a server instance exists, so a pending CreateFile() retry may proceed read_thread_started run() returns only once its read thread entered stop_token this read thread is to end - one connection ending, not the server server::stopping the server as a whole is shutting down and suppresses instance respawn instance::concluded read() returned holding no lock, so the instance joins without blocking

Windows "design" oddities If the pipe client connects and disconnects before the overlapped GetOverlappedResult() is called a waiting GetOverlappedResult() will hang and cannot be canceled via CancelIoEx(). https://learn.microsoft.com/en-us/windows/win32/fileio/canceling-pending-i-o-operations

Constructor & Destructor Documentation

◆ pipe()

template<typename rcv_t>
dx::pipe< rcv_t >::pipe ( const std::string & id,
decltype(listen)::listeners && listeners = {},
const ::DWORD(&) access[4] = access::dflt )
inlineprotected

◆ ~pipe()

template<typename rcv_t>
dx::pipe< rcv_t >::~pipe ( )
inlineoverrideprotected

Member Function Documentation

◆ dx_catchall_rethrow() [1/2]

template<typename rcv_t>
dx::pipe< rcv_t >::dx_catchall_rethrow ( "%s: handle:%llx access:%x:%x:%x:%x" ,
id. c_str(),
handle ,
access [0],
access [1],
access [2],
access [3] )
inlineoverrideprotectednoexcept

◆ dx_catchall_rethrow() [2/2]

template<::HANDLE invalid_t = INVALID_HANDLE_VALUE>
dx::resource< invalid_t >::dx_catchall_rethrow ( )
inlinenoexceptinherited

◆ operator const os_event()

template<::HANDLE invalid_t = INVALID_HANDLE_VALUE>
dx::resource< invalid_t >::operator const os_event ( ) const
inlinenoexceptinherited

◆ operator os_event()

template<::HANDLE invalid_t = INVALID_HANDLE_VALUE>
dx::resource< invalid_t >::operator os_event ( )
inlinenoexceptinherited

◆ operator::HANDLE()

template<::HANDLE invalid_t = INVALID_HANDLE_VALUE>
dx::resource< invalid_t >::operator::HANDLE ( ) const
inlinenoexceptinherited
Here is the caller graph for this function:

◆ operator<<()

template<typename rcv_t>
template<typename snd_t>
const snd_t & dx::pipe< rcv_t >::operator<< ( const snd_t & snd)
inlineprotected

◆ read()

template<typename rcv_t>
virtual void dx::pipe< rcv_t >::read ( std::stop_token stop_token)
inlineprotectedvirtualnoexcept

a client connect/disconnect racing the overlapped completion leaves it unwakeable by CancelIoEx(), hence polled against the stop token

Here is the caller graph for this function:

◆ run()

template<typename rcv_t>
void dx::pipe< rcv_t >::run ( )
inlineprotected

◆ session()

template<typename rcv_t>
::ULONG dx::pipe< rcv_t >::session ( ) const
inlineprotected

◆ this()

template<typename rcv_t>
template<typename rcv_t>
dx::pipe::status promoted dx::pipe< rcv_t >::this ( const os_result & value)
inlineprotected

Member Data Documentation

◆ access

template<typename rcv_t>
::DWORD dx::pipe< rcv_t >::access[4] {}
protected

◆ attach

template<typename rcv_t>
shared::event dx::pipe< rcv_t >::attach {id}
protected

◆ connect

template<typename rcv_t>
overlapped dx::pipe< rcv_t >::connect
protected

◆ ERROR_PIPE_BUSY

template<typename rcv_t>
dx::pipe::status dx::pipe< rcv_t >::ERROR_PIPE_BUSY
protected

◆ handle

template<::HANDLE invalid_t = INVALID_HANDLE_VALUE>
::HANDLE dx::resource< invalid_t >::handle = invalid_t
protectedinherited

◆ id

template<typename rcv_t>
std::string dx::pipe< rcv_t >::id
protected

◆ in

template<typename rcv_t>
overlapped dx::pipe< rcv_t >::in
protected

◆ listen

template<typename rcv_t>
dx_catchall (, "%s: handle:%llx", id.c_str(), handle) public listen<std::function<void(const rcv_t&)> > dx::pipe< rcv_t >::listen
protected

◆ out

template<typename rcv_t>
overlapped dx::pipe< rcv_t >::out
protected

◆ overlapped

template<typename rcv_t>
bool dx::pipe< rcv_t >::overlapped {}
protected

◆ process

template<::HANDLE invalid_t = INVALID_HANDLE_VALUE>
::HANDLE dx::resource< invalid_t >::process = ::GetCurrentProcess()
protectedinherited

◆ read_thread_started

template<typename rcv_t>
event<user> dx::pipe< rcv_t >::read_thread_started {}
protected

◆ stop_callback

template<typename rcv_t>
std::stop_callback<std::function<void()> > dx::pipe< rcv_t >::stop_callback {this->get_stop_token(), [this](){this->free();}}
protected

◆ this

template<typename rcv_t>
class dx::pipe::server dx::pipe< rcv_t >::this
protected

The documentation for this class was generated from the following file:

(c) copyright 2009 dynamic acoustics e.U. generated on

a closed source license may be obtained by requesting a written permission from dynamic acoustics e.U.
however - governmental use generally and military use especially is strictly prohibited though.