xentara-utils v1.2.1
Xentara utilities library
Loading...
Searching...
No Matches
xentara::utils::ipc::NamedPipeServer Class Referencefinal

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

#include <ipc/NamedPipeServer.hpp>

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

Public Types

enum class  Scope { User , Global }
 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.

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