PNP: TTCP

xiaoxiao2021-02-27  310

TTCP: Test TCP

https://en.wikipedia.org/wiki/Ttcp

协议

struct SessionMessage { int32_t number; int32_t length; } __attribute__ ((__packed__)); struct PayloadMessage { int32_t length; char data[0]; }

Code

https://github.com/huntinux/pnp/blob/master/ttcp/ttcp.cc

其他知识

__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
转载请注明原文地址: https://www.6miu.com/read-8728.html

最新回复(0)