Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
SC::NamedPipeServer Struct Reference

Named pipe server endpoint. More...

#include <File.h>

Public Member Functions

Result create (StringSpan name, NamedPipeServerOptions options={})
 Creates a named pipe server endpoint.
 
Result accept (PipeDescriptor &outConnection)
 Accept one client connection and return it as a connected PipeDescriptor.
 
Result close ()
 Closes the listening endpoint.
 

Detailed Description

Named pipe server endpoint.

Use create + accept to obtain connected PipeDescriptor pairs.

Note
See SC::NamedPipeClient for client-side connection.
Example:
SC::Result SC::FileTest::snippetForNamedPipeServer()
{
StringPath pipePath;
SC_TRY(NamedPipeName::build("sc-doc-example", pipePath));
NamedPipeServerOptions serverOptions;
serverOptions.connectionOptions.blocking = true;
serverOptions.posix.removeEndpointBeforeCreate = true;
SC_TRY(server.create(pipePath.view(), serverOptions));
PipeDescriptor clientConnection;
SC_TRY(NamedPipeClient::connect(pipePath.view(), clientConnection));
PipeDescriptor serverConnection;
SC_TRY(server.accept(serverConnection));
SC_TRY(clientConnection.writePipe.writeString("ping"));
char readBuffer[4] = {0};
Span<char> readData;
SC_TRY(serverConnection.readPipe.read({readBuffer, sizeof(readBuffer)}, readData));
StringSpan received(readData, false, StringEncoding::Ascii);
SC_TRY_MSG(received == "ping", "Unexpected payload");
SC_TRY(clientConnection.close());
SC_TRY(serverConnection.close());
SC_TRY(server.close());
return Result(true);
}

Member Function Documentation

◆ accept()

Result SC::NamedPipeServer::accept ( PipeDescriptor & outConnection)

Accept one client connection and return it as a connected PipeDescriptor.

Parameters
[out]outConnectionConnected read/write pipe handles.
Returns
Valid Result on success.

◆ close()

Result SC::NamedPipeServer::close ( )

Closes the listening endpoint.

Note
Safe to call multiple times.
Returns
Valid Result on success.

◆ create()

Result SC::NamedPipeServer::create ( StringSpan name,
NamedPipeServerOptions options = {} )

Creates a named pipe server endpoint.

Parameters
namePlatform-native absolute endpoint name. Use filesystem absolute paths on POSIX and \\.\pipe\... or \\?\pipe\... on Windows. See SC::NamedPipeName::build for a cross-platform helper.
optionsServer creation options.
Returns
Valid Result if create succeeds.

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