[ENet-discuss] ENET_HOST_TO_NET/ENET_NET_TO_HOST

dmex dmex04 at gmail.com
Sun Jul 14 03:27:12 PDT 2013


Hello,

On Windows the htons/htonl/ntohs/ntohl functions are much older and slower
than the same functions found on other Operating Systems since the Windows
versions of these functions do not make use of the native bswap processor
instruction.

Intrinsic functions are available in both stdlib.h and intrin.h on multiple
platforms for solving this issue, you can simply define the following in
win32.h or enet.h for slightly better enet library performance:

#define ntohl(x)  _byteswap_ulong(x)
#define ntohs(x) _byteswap_ushort(x)
#define htonl(x) _byteswap_ulong(x)
#define htons(x) _byteswap_ushort(x)

#define ENET_HOST_TO_NET_16(value) (htons(value))
#define ENET_HOST_TO_NET_32(value) (htonl(value))
#define ENET_NET_TO_HOST_16(value) (ntohs(value))
#define ENET_NET_TO_HOST_32(value) (ntohl(value))

Would it be possible to include these in the enet library by default?

-dmex



More information about the ENet-discuss mailing list