TTCP: Test TCP
协议
struct SessionMessage
{
int32_t number;
int32_t length;
} __attribute__ ((__packed__));
struct PayloadMessage
{
int32_t length;
char data[0];
}
Code
其他知识
__attribute__((packed))
http://stackoverflow.com/questions/1756811/does-gccs-attribute-packed-retain-the-original-ordering
在使用struct描述网络包的时候,使用“__attribute__(packed)”能保证struct中的member之间没有gap:
struct packet {
uint8_t x;
uint32_t y;
} __attribute__((packed)); // sizeof 为 5
struct packet {
uint8_t x;
uint32_t y;
} ; // sizeof 为 8