MOOON distributed message structure

Source: Internet
Author: User
Tags constant definition

 The main message structure of MOOON is as follows. The disadvantage is that the message occupies a large number of bytes:

 
 
  1. // Why do I need to differentiate between IPV4 and IPV6?
  2. // If only IPV4 is supported, a single IP address only needs to be represented in four bytes,
  3. // In this way, the source and destination IP addresses save a total of 24 bytes;
  4. // When IPV6 is supported, it is also compatible with IPV4, but 24 bytes are wasted for IPV4;
  5. // The Source and target IP addresses, either IPV4 or IPV6, cannot cross-appear.
  6. # Ifdef IPV6_SUPPORTED
  7. # Define IP_BYTES (4*4) // IPV6 address Length
  8. # Else
  9. # Define IP_BYTES 4 // IPV4 address Length
  10. # Endif
  11.  
  12. //////////////////////////////////////// ////////////////////////////////////////
  13. SCHED_NAMESPACE_BEGIN
  14.  
  15. /***
  16. * Constant definition
  17. */
  18. Enum
  19. {
  20. INVALID_SERVICE_ID = 0,
  21. INVALID_SESSION_ID = 0, // invalid SessionId
  22. SERVICE_ID_MAX = 100, // The maximum Service ID value. The value starts from 1.
  23. SESSION_ID_MAX = 10000 // The maximum Session ID value. The value starts from 1.
  24. };
  25.  
  26. // 4-byte alignment
  27. # Pragma pack (4)
  28.  
  29. /***
  30. * Distributed message Flags Structure
  31. * Why Should Flags be defined as a struct,
  32. * Because the nuint32_t type does not support bit expression,
  33. * Use struct for a layer conversion to achieve the same purpose
  34. */
  35. Typedef struct TDistributedMessageFlags
  36. {
  37. // Use union to facilitate operations
  38. Union Flags
  39. {
  40. Uint32_t flags;
  41. Struct TFlagsBits
  42. {
  43. Uint32_t ip_type: 1; // ip address type; optional values: net: IP_TYPE_4 or net: IP_TYPE_6
  44. Uint32_t reserved: 31; // reserved Bit
  45. } Flags_bits;
  46. } Flags;
  47.  
  48. TDistributedMessageFlags (uint32_t v)
  49. : Flags (v)
  50. {
  51. }
  52. } Distribted_message_flags_t;
  53.  
  54. /***
  55. * Distributed message header Structure
  56. */
  57. Typedef struct TDistributedMessage
  58. {
  59. Net: common_message_header header; // Message header
  60. Nuint32_t flags; // flag field
  61.  
  62. Nuint32_t source_ip [IP_BYTES]; // the source IP address. If it is an IPV4 address, the value of N is 1; otherwise, the value of 4
  63. Nuint32_t destination_ip [IP_BYTES]; // ip address of the Message destination. If it is an IPV4 address, the value of N is 1; otherwise, the value of 4
  64.  
  65. Nuint16_t source_port; // The source port number.
  66. Nuint16_t destination_port; // The port number of the Message destination
  67.  
  68. Nuint32_t source_service_id; // destination_Service ID
  69. Nuint32_t destination_service_id; // Service ID of the Message destination
  70.  
  71. Nuint32_t source_session_id; // destination_Session ID
  72. Nuint32_t destination_session_id; // Session ID of the Message destination
  73.  
  74. Nuint32_t source_sequence_number; // serial number, starting from 0 and increasing sequentially until re-occurrence, used to solve timed_wait problems similar to TCP
  75. Nuint32_t destination_sequence_number; // serial number, starting from 0 and increasing sequentially until re-occurrence, used to solve timed_wait problems similar to TCP
  76.  
  77. Nuint32_t source_thread_affinity; // The value of the thread to establish a binding relationship with the thread.
  78. Nuint32_t destination_thread_affinity; // The value of the thread to establish a binding relationship with the thread.
  79.  
  80. Char data [0]; // message content
  81.  
  82. Std: string to_string () const;
  83. } Distribted_message_t;
  84.  
  85. # Pragma pack ()
  86.  
  87. Inline bool is_valid_service (uint32_t service_id)
  88. {
  89. Return service_id> 0
  90. & Service_id <= SERVICE_ID_MAX;
  91. }
  92.  
  93. Inline bool is_valid_session (uint32_t session_id)
  94. {
  95. Return session_id> 0
  96. & Session_id <= SESSION_ID_MAX;
  97. }
  98.  
  99. //////////////////////////////////////// ////////////////////////////////////////
  100. SCHED_NAMESPACE_END

:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/164HMF3-0.jpg "border =" 0 "alt =" "/>

 

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

Related Article

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.