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