Class Server

Nested Relationships

Nested Types

Class Documentation

class Server

Cross-platform Utility class that provides the ability to wait for activity on multiple sockets at once (including both connected clients and listening sockets), and call out to provided handlers when that activity occurs.

Public Types

typedef void (*ActivityCallback)(Endpoint *endpoint, void *userData)

Function signature for callback that is invoked when activity occurs on a connected socket endpoint.

Param endpoint

The socket endpoint experiencing activity

Param userData

Pointer to opaque user data provided to the Start() method

Public Functions

Server()
~Server()
Server(const Server&) = delete
Server &operator=(const Server&) = delete
void Start(uint16_t port, ActivityCallback callback = nullptr, void *userData = nullptr)

Start listening on a TCP socket.

Parameters
  • port -- Port number on which to listen.

  • callback -- Implementation of ActivityCallback, invoked when activity occurs on a managed socket endpoint.

  • userData -- Opaque pointer to user-owned data that is provided to the callback when invoked.

void Start(TCHAR const *ipcPath, ActivityCallback callback = nullptr, void *userData = nullptr)

Start listening on an inter-process communication socket.

Parameters
  • port -- Socket or named-pipe filename to use; can be absolute or relative, but it must be something accessible to potential client endpoints.

  • callback -- Implementation of ActivityCallback, invoked when activity occurs on a managed socket endpoint.

  • userData -- Opaque pointer to user-owned data that is provided to the callback when invoked.

bool CheckForActivity(size_t timeoutMS)

Wait for activity on the current listening socket and any managed connected client endpoint sockets.

Parameters

timeoutMS -- Number of milliseconds to wait for activity on any managed socket.

Returns

True if there was activity, or there was no activity before timeoutMS expired; false if there was an error on the listening socket (for example, the socket was closed via a call to Stop()). A return value of false can be interpreted as a signal that the socket server can be shut down.

void SetDefaultReadListenSize(size_t readSizeInBytes)

Set size of buffer to use for listening on connected pipes for communication.

Parameters

readSizeInBytes -- Size of buffer; 0 specifies no listening for connected pipe activity. (default 0)

void SetShutdownEvent()

Set an Event used for monitoring whether the rest of injector is attempting to shut down.

void Stop()

Close the listening socket and any connected client endpoints, and shutdown cleanly.

struct Private