Mooon-server New Message Processing interface

Source: Internet
Author: User

Mooon-server provides a common TCP framework and abstracts the Ipackethandler interface for packet parsing, which provides unrestricted latitude, supports any protocol, but increases the complexity of the usage.

Because most protocols will define a large small segment of the message packet, based on this premise, mooon-server references the new interface Imessageobserver, which can parse any message that the header is Net::tcommonmessageheader. After a package parsing is complete (both headers and packages have received completion), the message is passed to the consumer by a callback On_message (), which greatly simplifies the mooon-server programming.

The following is the definition of an interface:

/*** * Message Viewer * Call if you receive a full message * If your message header and Net::tcommonmessageheader are consistent, * then suggest using imessageobserver instead of Ipackethandler, * Imessageobserver is a higher level interface than Ipackethandler/class Callback_interface Imessageobserver {public:virtual ~IMessage Observer () {}/*** * received a full message when the callback * @request_header input parameters, received the message header * @request_body input parameters, received Message body * Here it is necessary to note that the framework does not release request_body memory and requires the user to release the * Release method: delete []request_body; otherwise there will be a memory leak * @re    
      Sponse_buffer output parameters, sent to the end-to-end response, the default value is NULL * Please note that *response_buffer must be new char[], * and will be delete by frame [] it * @response_size output parameter, the number of response data bytes that need to be sent to the end, the default value is 0 * @return processing successfully returns TRUE, otherwise return FALSE */virtual bool on    
                          _message (const net::tcommonmessageheader& request_header, const char* Request_body    
        
    , char** Response_buffer, size_t* response_sizer) = 0; /***    
      *Connection is turned off/virtual void on_connection_closed () {}/*** * Connection Timeout * @return If true, confirm that Connection timeout, connection will be closed *; otherwise, the connection will continue to be used, while the timestamp will be updated/virtual bool On_connection_timeout () {RET
    Urn true; /*** * Packet sent after the callback * @return Util::handle_continue means not to close the connection to continue to use, * return to other values will close the connection/Virtu  Al util::handle_result_t on_response_completed () {//return util::handle_close;//Short connection return Util::handle_continue; Long connection};

This article is from the "Flying Month" blog, please be sure to keep this source http://mooon.blog.51cto.com/1246491/941084

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.