xentara-utils v2.1
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::ipc::NamedPipeServer Class Referencefinal

A class to create a named pipe server. More...

#include <xentara/utils/ipc/NamedPipeServer.hpp>

+ Inheritance diagram for xentara::utils::ipc::NamedPipeServer:

Public Types

enum class  Scope { User , Global , Service }
 Scopes for names pipe servers. More...
 

Public Member Functions

 NamedPipeServer ()=default
 Default constructor.
 
 NamedPipeServer (std::reference_wrapper< const io::StopSource > stopSource) noexcept
 Constructor that associates a stop source with the named pipe server.
 
 NamedPipeServer (std::string_view name, Scope scope)
 Constructor that listens for client connections.
 
 NamedPipeServer (std::string_view name, Scope scope, std::reference_wrapper< const io::StopSource > stopSource)
 Constructor that listens for client connections using a stop source.
 
auto setStopSource (const io::StopSource &stopSource) noexcept -> void
 Associates a stop source with the named pipe.
 
auto removeStopSource () noexcept -> void
 Removes any associated stop source from the named pipe.
 
auto listen (std::string_view name, Scope scope) -> void
 Listens for client connections.
 
auto accept () -> NamedPipe
 Accepts a client connection.
 
auto accept (std::optional< std::chrono::nanoseconds > timeout) -> NamedPipe
 Accepts a client connection.
 
auto close () -> void
 Closes the connection of socket/handler.
 

Detailed Description

A class to create a named pipe server.

Member Enumeration Documentation

◆ Scope

Scopes for names pipe servers.

Enumerator
User 

Only the creator can connect.

Global 

All users can connect.

Service 

Only the creator can connect, unless the current process is running as a Windows service.

    This option allows you restrict access to the creator of the pipe, unless the current process ir running as a
    Windows service under one of the built-in Windows [Service User Accounts](https://learn.microsoft.com/en-us/windows/win32/services/service-user-accounts).

    Normally, debug and diagnostics access should be restricted to the user running the application. If the
    application is running as a service under one of the built-in Service User Accounts, however, this is not
    very useful, because diagnositcs tools cannot be run under a service account. In that case,
    all users should have diagnosics access.

    If you use this option, then only the creator will be able to connect if the current process is running as a regular
    Application. If the current process is running as a Windows service running under the 
    [LocalService](https://learn.microsoft.com/en-us/windows/win32/services/localservice-account),
    [NetworkService ](https://learn.microsoft.com/en-us/windows/win32/services/networkservice-account), or
    [LocalSystem ](https://learn.microsoft.com/en-us/windows/win32/services/localsystem-account Account, all users will
    be able to connect. If the callung process is running as a Windows service, but the service has been configured to run
    under a regular user account, only the creator will be able to connect, as with a regular application.
    @see @ref windows::service::isSystemService(). 

Constructor & Destructor Documentation

◆ NamedPipeServer() [1/4]

xentara::utils::ipc::NamedPipeServer::NamedPipeServer ( )
default

Default constructor.

◆ NamedPipeServer() [2/4]

xentara::utils::ipc::NamedPipeServer::NamedPipeServer ( std::reference_wrapper< const io::StopSource >  stopSource)
explicitnoexcept

Constructor that associates a stop source with the named pipe server.

◆ NamedPipeServer() [3/4]

xentara::utils::ipc::NamedPipeServer::NamedPipeServer ( std::string_view  name,
Scope  scope 
)

Constructor that listens for client connections.

Parameters
nameThe name to listen to
scopeThe scope
Exceptions
std::runtime_errorAn error occurred listening to the pipe name

◆ NamedPipeServer() [4/4]

xentara::utils::ipc::NamedPipeServer::NamedPipeServer ( std::string_view  name,
Scope  scope,
std::reference_wrapper< const io::StopSource >  stopSource 
)

Constructor that listens for client connections using a stop source.

Parameters
nameThe name to listen to
scopeThe scope
stopSourceThe stop source to associates with the named pipe server
Exceptions
std::runtime_errorAn error occurred listening to the pipe name

Member Function Documentation

◆ accept() [1/2]

auto xentara::utils::ipc::NamedPipeServer::accept ( ) -> NamedPipe

Accepts a client connection.

Returns
The accepted socket. If the named pipe server has a stop source associated with it, the returned object will use the same stop source.
Exceptions
io::StopRequestedThe stop source associated with the named pipe server was triggered.
std::runtime_errorAn error occurred accepting the connection

◆ accept() [2/2]

auto xentara::utils::ipc::NamedPipeServer::accept ( std::optional< std::chrono::nanoseconds >  timeout) -> NamedPipe

Accepts a client connection.

Parameters
timeoutThe timeout, or std::nullopt to use an infinite timeout.
Returns

The accepted socket, or a default constructed named pipe on timeout. You can use the [operator bool()]NamedPipe::operator bool()) to check whether the returned named pipe is valid.

If the named pipe server has a stop source associated with it, the returned object will use the same stop source.

Exceptions
io::StopRequestedThe stop source associated with the named pipe server was triggered.
std::runtime_errorAn error occurred accepting the connection

◆ close()

auto xentara::utils::ipc::NamedPipeServer::close ( ) -> void

Closes the connection of socket/handler.

◆ listen()

auto xentara::utils::ipc::NamedPipeServer::listen ( std::string_view  name,
Scope  scope 
) -> void

Listens for client connections.

Parameters
nameThe name to listen to
scopeThe scope
Exceptions
std::runtime_errorAn error occurred

◆ removeStopSource()

auto xentara::utils::ipc::NamedPipeServer::removeStopSource ( ) -> void
noexcept

Removes any associated stop source from the named pipe.

◆ setStopSource()

auto xentara::utils::ipc::NamedPipeServer::setStopSource ( const io::StopSource &  stopSource) -> void
noexcept

Associates a stop source with the named pipe.

If you set a stop source, accept() will throw an exception of type io::StopRequested if a stop is requested on the stop source.

Parameters
stopSourceThe stop source to associates with the named pipe server