coral
A C++ library for distributed co-simulation
|
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... | |
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.
|
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.
[in] | protocolIdentifier | The identifier for the protocol with which the request was made. |
[in] | protocolVersion | The version number of the protocol with which the request was made. |
[in] | requestHeader | A 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] | requestHeaderSize | The length (in bytes) of the request header. |
[in] | requestBody | A 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] | requestBodySize | The length (in bytes) of the request body if requestBody is not null, otherwise unspecified. |
[out] | replyHeader | On 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] | replyHeaderSize | On successful return, this must contain the length of the reply header. If the function returns false , this parameter is ignored. |
[out] | replyBody | On 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] | replyBodySize | If 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. |