Class NamedPipeEndpoint

Inheritance Relationships

Base Type

Class Documentation

class NamedPipeEndpoint : public gpa::network::Endpoint

Concrete Endpoint implementation based on named pipes API. This implementation is only available on Windows-based systems.

Public Functions

NamedPipeEndpoint()
NamedPipeEndpoint(HANDLE pipe, TCHAR const *pathname)
NamedPipeEndpoint(HANDLE pipe, HANDLE hEvent, TCHAR const *pathname)
NamedPipeEndpoint(NamedPipeEndpoint const&) = delete
NamedPipeEndpoint &operator=(NamedPipeEndpoint const&) = delete
virtual ~NamedPipeEndpoint()
void Listen(TCHAR const *pathname)

Establish a named pipe at pathname, and begin listening on it.

Note

This path must be accessible to any potential client sockets.

Parameters

pathname -- Absolute or relative path to the Unix-domain socket file.

bool Connect(TCHAR const *pathname)

Connect to a previously-established named pipe listening at the pathname specified in pathname. Intended for connecting asynchronously.

Parameters

pathname -- Absolute or relative path to the named pipe.

virtual bool WaitRead(uint64_t readLengthInBytes) override

Async-only variant; wrapper around internal variant used for both.

Parameters

readLengthInBytes -- Length of bytes to read and allocate internal tmp storage for.

bool WaitRead(void *destBuffer, uint64_t readLengthInBytes)

Internal variant; takes in non-nullptr destBuffer for use in synchronous Read.

Parameters
  • destBuffer -- Buffer to store read data, or nullptr to use tmp internal storage

  • readLengthInBytes -- Length of bytes to read and/or allocate internal tmp storage for.

virtual bool IsWaitingOnRead() override

Whether we have an active WaitRead waiting on input from the pipe.

Returns

True if currently waiting on read operation to complete.

virtual uint64_t Read(void *destBuffer, uint64_t readLengthInBytes) override

Read a prescribed number of bytes from the endpoint into a provided byte buffer.

Parameters
  • destBuffer -- Buffer to receive byte data from the endpoint.

  • readLengthInBytes -- Number of bytes to read; this number should not exceed the size of the destination buffer in bytes.

Returns

Number of bytes actually read.

virtual uint64_t Write(void const *srcBuffer, uint64_t writeLengthInBytes) override

Sync-only write.

Parameters
  • srcBuffer -- Buffer to write

  • writeLengthInBytes -- Length to write

virtual Endpoint *Accept(uint64_t timeoutMS) override

Finish connecting to client pipe, create a new pipe instance to listen for new connections, and return connected endpoint.

Parameters

timeoutMS -- Unused

virtual void Shutdown() override

Close the socket and clean up the endpoint. This will produce a "connection reset" error on the connected peer (server or client endpoint).

virtual uint64_t Handle() const override

Obtain the file descriptor corresponding to the network endpoint.

This is typically useful in server applications where for efficiency reasons, the server must wait for activity on multiple endpoints at once, using low-level API calls that deal with integer file descriptors.

Returns

The current value of the socket endpoint's file descriptor (default: -1)

virtual uint64_t EventHandle() const override

Get Handle for Event tracking on endpoint.

Returns

The current value of the socket endpoint's event handle (default: -1)

virtual bool IsEndpointBroken() const override

Whether or not endpoint has encountered handled fatal error. If function returns true, but has encountered a novel fatal error code, add that and any necessary handling.

Returns

False if pipe hasn't encountered known fatal error in operations.

void HandlePipeError()