coral
A C++ library for distributed co-simulation
Public Member Functions | List of all members
coral::net::reqrep::ServerProtocolHandler Class Referenceabstract

An interface for classes that implement the server side of request-reply protocols, to be used with Server. More...

#include "coral/net/reqrep.hpp"

Public Member Functions

virtual bool HandleRequest (const std::string &protocolIdentifier, std::uint16_t protocolVersion, const char *requestHeader, size_t requestHeaderSize, const char *requestBody, size_t requestBodySize, const char *&replyHeader, size_t &replyHeaderSize, const char *&replyBody, size_t &replyBodySize)=0
 Handles an incoming request and generates a reply. More...
 

Detailed Description

An interface for classes that implement the server side of request-reply protocols, to be used with Server.

Objects of this type may be added to a Server and associated with a particular protocol and a specific version of that protocol. Whenever a Server receives an incoming request, it routes the request to the corresponding handler.

One implementation may handle multiple protocols and/or multiple versions of the same protocol, by calling Server::AddProtocolHandler() several times with the same object.

Member Function Documentation

virtual bool coral::net::reqrep::ServerProtocolHandler::HandleRequest ( const std::string protocolIdentifier,
std::uint16_t  protocolVersion,
const char *  requestHeader,
size_t  requestHeaderSize,
const char *  requestBody,
size_t  requestBodySize,
const char *&  replyHeader,
size_t &  replyHeaderSize,
const char *&  replyBody,
size_t &  replyBodySize 
)
pure virtual

Handles an incoming request and generates a reply.

Each request/reply consists of a mandatory header and an optional body, the contents and format of which are left to the implementor. If the request is invalid, or for some other reason should be ignored, the function may return false, in which case the server will not send a reply.

Parameters
[in]protocolIdentifierThe identifier for the protocol with which the request was made.
[in]protocolVersionThe version number of the protocol with which the request was made.
[in]requestHeaderA pointer to the start of a memory buffer which holds the request header, the length of which is given by requestHeaderSize. This is never null, but may be empty (i.e., zero length).
[in]requestHeaderSizeThe length (in bytes) of the request header.
[in]requestBodyA pointer to the start of a memory buffer which holds the request body, the length of which is given by requestBodySize. Iff the request has no body, this will be null.
[in]requestBodySizeThe length (in bytes) of the request body if requestBody is not null, otherwise unspecified.
[out]replyHeaderOn successful return, this must contain a pointer to a memory buffer which holds the reply header, whose length is given by replyHeaderSize. The pointer may not be null in this case, even if the header is empty. The memory buffer and its contents must remain valid until the next call to HandleRequest() or until the object is destroyed, whichever comes first. If the function returns false, this parameter is ignored.
[out]replyHeaderSizeOn successful return, this must contain the length of the reply header. If the function returns false, this parameter is ignored.
[out]replyBodyOn successful return, this may be set to a pointer to a memory buffer which holds the reply header, whose length is given by replyBodySize. Setting it to null signifies that the reply has no body. If non-null, the memory buffer and its contents must remain valid until the next call to HandleRequest() or until the object is destroyed, whichever comes first. If the function returns false, this parameter is ignored.
[out]replyBodySizeIf replyBody is not null, this must contain the length of the reply header on successful return. If the function returns false, this parameter is ignored.
Returns
Whether the request was successfully handled and a reply should be sent.

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