#ifndef __ReplyToClient_h_ #define __ReplyToClient_h_ #include #include "Messages.h" #include "CommandDispatcher.h" #include "SmarterP.h" /* * Send a message to the client. The MessageId comes from the * original request from the client. There are three formats * only for performance reasons. */ void addToOutputQueue(SocketInfo *socket, std::string const &messageBody, ExternalRequest::MessageId messageId = ExternalRequest::MessageId::none()); void addToOutputQueue(SocketInfo *socket, std::string &&messageBody, ExternalRequest::MessageId messageId = ExternalRequest::MessageId::none()); void addToOutputQueue(SocketInfo *socket, SmarterCP< std::string > const &messageBody, ExternalRequest::MessageId messageId = ExternalRequest::MessageId::none()); /* This will wait until all of the data has been sent to the client * (or at least to the o/s). Then it will do a graceful close to * the connection. We typically use this after saying "No automatic * retries." The client will receive that message. */ void closeWhenOutputQueueIsEmpty(SocketInfo *socket); /* * Each client can get it's output in a different format. Usually the * client requests the format that it wants. This enum is public only * for some special cases where a program will use `initReplyToClient()` * to set the default output mode. */ enum ReplySerializer { rtcTextSerializer, /* Aimed at a user on telnet. But sends the * message length and id in such a way that a * computer can also decode it. */ rtcZLibSerializer, /* Compress everything with zlib. One four byte * integer for the message id, and one for the * message length. This only exists for very old * clients. Newer clients all use 64 bit integers * for the message id. */ rtcZLib1Serializer, /* Same as the previous option, but we add some * extra fields for error checking. */ rtcZLib64Serializer, /* Same as rtcZLibSerializer but the message id is * 64 bits rather than 32. This is the preferred * option for new development. */ rtcLiteralSerializer, /* Ignore message id and message boundaries. Simply * send each message body as is. */ rtcSimpleSerializer, /* This is aimed at the javascript proxy. It * provides the body and the id. It uses no * compression or anything else that's not * essential. Deprecated. New projects should * all use rtcSimple64Serializer instead. We might * have a brief period of overlap. */ rtcSimple64Serializer /* This is aimed at the javascript proxy. It * provides the body and the id. It uses no * compression or anything else that's not * essential. The message size is limited to 32 * bits but the message id can be 64 bits, same as * rtcZLib64Serializer. */ }; // Warning: Only the first call to initReplyToClient() will set the // defaultSerializer. If there are multiple calls to initReplyToClient(), // only the first one will do anything and the rest will be ignored. // initPing() (and many other things) will create the default // CommandDispatcher. CommandDispatcher::CommandDispatcher() will call // connectToReplyToClient(). connectToReplyToClient() will call // initReplyToClient() with the default argument. // // This was not always the case. So old code might be broken. I don't think // that's a problem. alert_proxy_server/ProxyMain.C and // semaphore_manager/SemaphoreMain.C seem to be the only files which call // initReplyToClient() with a non-default argument, and they seem to be // okay. void initReplyToClient(ReplySerializer defaultSerializer = rtcTextSerializer); // Each instance of a CommandDispatcher will automatically call this. // No one else should call this. void connectToReplyToClient(CommandDispatcher *commandDispatcher); #endif