The main message structure of MOOON is as follows. The disadvantage is that the message occupies a large number of bytes:
- // Why do I need to differentiate between IPV4 and IPV6?
- // If only IPV4 is supported, a single IP address only needs to be represented in four bytes,
- // In this way, the source and destination IP addresses save a total of 24 bytes;
- // When IPV6 is supported, it is also compatible with IPV4, but 24 bytes are wasted for IPV4;
- // The Source and target IP addresses, either IPV4 or IPV6, cannot cross-appear.
- # Ifdef IPV6_SUPPORTED
- # Define IP_BYTES (4*4) // IPV6 address Length
- # Else
- # Define IP_BYTES 4 // IPV4 address Length
- # Endif
-
- //////////////////////////////////////// ////////////////////////////////////////
- SCHED_NAMESPACE_BEGIN
-
- /***
- * Constant definition
- */
- Enum
- {
- INVALID_SERVICE_ID = 0,
- INVALID_SESSION_ID = 0, // invalid SessionId
- SERVICE_ID_MAX = 100, // The maximum Service ID value. The value starts from 1.
- SESSION_ID_MAX = 10000 // The maximum Session ID value. The value starts from 1.
- };
-
- // 4-byte alignment
- # Pragma pack (4)
-
- /***
- * Distributed message Flags Structure
- * Why Should Flags be defined as a struct,
- * Because the nuint32_t type does not support bit expression,
- * Use struct for a layer conversion to achieve the same purpose
- */
- Typedef struct TDistributedMessageFlags
- {
- // Use union to facilitate operations
- Union Flags
- {
- Uint32_t flags;
- Struct TFlagsBits
- {
- Uint32_t ip_type: 1; // ip address type; optional values: net: IP_TYPE_4 or net: IP_TYPE_6
- Uint32_t reserved: 31; // reserved Bit
- } Flags_bits;
- } Flags;
-
- TDistributedMessageFlags (uint32_t v)
- : Flags (v)
- {
- }
- } Distribted_message_flags_t;
-
- /***
- * Distributed message header Structure
- */
- Typedef struct TDistributedMessage
- {
- Net: common_message_header header; // Message header
- Nuint32_t flags; // flag field
-
- 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
- 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
-
- Nuint16_t source_port; // The source port number.
- Nuint16_t destination_port; // The port number of the Message destination
-
- Nuint32_t source_service_id; // destination_Service ID
- Nuint32_t destination_service_id; // Service ID of the Message destination
-
- Nuint32_t source_session_id; // destination_Session ID
- Nuint32_t destination_session_id; // Session ID of the Message destination
-
- 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
- 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
-
- Nuint32_t source_thread_affinity; // The value of the thread to establish a binding relationship with the thread.
- Nuint32_t destination_thread_affinity; // The value of the thread to establish a binding relationship with the thread.
-
- Char data [0]; // message content
-
- Std: string to_string () const;
- } Distribted_message_t;
-
- # Pragma pack ()
-
- Inline bool is_valid_service (uint32_t service_id)
- {
- Return service_id> 0
- & Service_id <= SERVICE_ID_MAX;
- }
-
- Inline bool is_valid_session (uint32_t session_id)
- {
- Return session_id> 0
- & Session_id <= SESSION_ID_MAX;
- }
-
- //////////////////////////////////////// ////////////////////////////////////////
- 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