aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authoreihrul <eihrul>2010-03-22 17:17:07 +0000
committereihrul <eihrul>2010-03-22 17:17:07 +0000
commit2be268a77bee17ae7bf47ffbcbb4f4d68d81608d (patch)
treecafb2e44a8d16b9931622af8f9865690f7eabdb3 /include
parentea38380174da5ba0f94b627c946f7faf9469c1ae (diff)
downloadenet-2be268a77bee17ae7bf47ffbcbb4f4d68d81608d.tar.gz
enet-2be268a77bee17ae7bf47ffbcbb4f4d68d81608d.zip
packed structs
Diffstat (limited to 'include')
-rw-r--r--include/enet/callbacks.h2
-rw-r--r--include/enet/enet.h14
-rw-r--r--include/enet/protocol.h73
3 files changed, 51 insertions, 38 deletions
diff --git a/include/enet/callbacks.h b/include/enet/callbacks.h
index be29ae0..0b9e693 100644
--- a/include/enet/callbacks.h
+++ b/include/enet/callbacks.h
@@ -7,7 +7,7 @@
#include <stdlib.h>
-typedef struct
+typedef struct _ENetCallbacks
{
void * (ENET_CALLBACK * malloc) (size_t size);
void (ENET_CALLBACK * free) (void * memory);
diff --git a/include/enet/enet.h b/include/enet/enet.h
index cf7b2d0..dca564c 100644
--- a/include/enet/enet.h
+++ b/include/enet/enet.h
@@ -23,25 +23,25 @@ extern "C"
#include "enet/list.h"
#include "enet/callbacks.h"
-typedef enum
+typedef enum _ENetVersion
{
ENET_VERSION = 1
} ENetVersion;
-typedef enum
+typedef enum _ENetSocketType
{
ENET_SOCKET_TYPE_STREAM = 1,
ENET_SOCKET_TYPE_DATAGRAM = 2
} ENetSocketType;
-typedef enum
+typedef enum _ENetSocketWait
{
ENET_SOCKET_WAIT_NONE = 0,
ENET_SOCKET_WAIT_SEND = (1 << 0),
ENET_SOCKET_WAIT_RECEIVE = (1 << 1)
} ENetSocketWait;
-typedef enum
+typedef enum _ENetSocketOption
{
ENET_SOCKOPT_NONBLOCK = 1,
ENET_SOCKOPT_BROADCAST = 2,
@@ -83,7 +83,7 @@ typedef struct _ENetAddress
@sa ENetPacket
*/
-typedef enum
+typedef enum _ENetPacketFlag
{
/** packet must be received by the target peer and resend attempts should be
* made until the packet is delivered */
@@ -161,7 +161,7 @@ typedef struct _ENetIncomingCommand
ENetPacket * packet;
} ENetIncomingCommand;
-typedef enum
+typedef enum _ENetPeerState
{
ENET_PEER_STATE_DISCONNECTED = 0,
ENET_PEER_STATE_CONNECTING = 1,
@@ -319,7 +319,7 @@ typedef struct _ENetHost
/**
* An ENet event type, as specified in @ref ENetEvent.
*/
-typedef enum
+typedef enum _ENetEventType
{
/** no event occurred within the specified time limit */
ENET_EVENT_TYPE_NONE = 0,
diff --git a/include/enet/protocol.h b/include/enet/protocol.h
index 363857b..4e61cad 100644
--- a/include/enet/protocol.h
+++ b/include/enet/protocol.h
@@ -19,7 +19,7 @@ enum
ENET_PROTOCOL_MAXIMUM_PEER_ID = 0x7FFF
};
-typedef enum
+typedef enum _ENetProtocolCommand
{
ENET_PROTOCOL_COMMAND_NONE = 0,
ENET_PROTOCOL_COMMAND_ACKNOWLEDGE = 1,
@@ -38,7 +38,7 @@ typedef enum
ENET_PROTOCOL_COMMAND_MASK = 0x0F
} ENetProtocolCommand;
-typedef enum
+typedef enum _ENetProtocolFlag
{
ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE = (1 << 7),
ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED = (1 << 6),
@@ -47,28 +47,37 @@ typedef enum
ENET_PROTOCOL_HEADER_FLAG_MASK = 0x8000
} ENetProtocolFlag;
-typedef struct
+#ifdef _MSC_VER_
+#pragma pack(push, 1)
+#define ENET_PACKED
+#elif defined(__GNUC__)
+#define ENET_PACKED __attribute__ ((packed))
+#else
+#define ENET_PACKED
+#endif
+
+typedef struct _ENetProtocolHeader
{
enet_uint32 checksum;
enet_uint16 peerID;
enet_uint16 sentTime;
-} ENetProtocolHeader;
+} ENET_PACKED ENetProtocolHeader;
-typedef struct
+typedef struct _ENetProtocolCommandHeader
{
enet_uint8 command;
enet_uint8 channelID;
enet_uint16 reliableSequenceNumber;
-} ENetProtocolCommandHeader;
+} ENET_PACKED ENetProtocolCommandHeader;
-typedef struct
+typedef struct _ENetProtocolAcknowledge
{
ENetProtocolCommandHeader header;
enet_uint16 receivedReliableSequenceNumber;
enet_uint16 receivedSentTime;
-} ENetProtocolAcknowledge;
+} ENET_PACKED ENetProtocolAcknowledge;
-typedef struct
+typedef struct _ENetProtocolConnect
{
ENetProtocolCommandHeader header;
enet_uint16 outgoingPeerID;
@@ -81,9 +90,9 @@ typedef struct
enet_uint32 packetThrottleAcceleration;
enet_uint32 packetThrottleDeceleration;
enet_uint32 sessionID;
-} ENetProtocolConnect;
+} ENET_PACKED ENetProtocolConnect;
-typedef struct
+typedef struct _ENetProtocolVerifyConnect
{
ENetProtocolCommandHeader header;
enet_uint16 outgoingPeerID;
@@ -95,55 +104,55 @@ typedef struct
enet_uint32 packetThrottleInterval;
enet_uint32 packetThrottleAcceleration;
enet_uint32 packetThrottleDeceleration;
-} ENetProtocolVerifyConnect;
+} ENET_PACKED ENetProtocolVerifyConnect;
-typedef struct
+typedef struct _ENetProtocolBandwidthLimit
{
ENetProtocolCommandHeader header;
enet_uint32 incomingBandwidth;
enet_uint32 outgoingBandwidth;
-} ENetProtocolBandwidthLimit;
+} ENET_PACKED ENetProtocolBandwidthLimit;
-typedef struct
+typedef struct _ENetProtocolThrottleConfigure
{
ENetProtocolCommandHeader header;
enet_uint32 packetThrottleInterval;
enet_uint32 packetThrottleAcceleration;
enet_uint32 packetThrottleDeceleration;
-} ENetProtocolThrottleConfigure;
+} ENET_PACKED ENetProtocolThrottleConfigure;
-typedef struct
+typedef struct _ENetProtocolDisconnect
{
ENetProtocolCommandHeader header;
enet_uint32 data;
-} ENetProtocolDisconnect;
+} ENET_PACKED ENetProtocolDisconnect;
-typedef struct
+typedef struct _ENetProtocolPing
{
ENetProtocolCommandHeader header;
-} ENetProtocolPing;
+} ENET_PACKED ENetProtocolPing;
-typedef struct
+typedef struct _ENetProtocolSendReliable
{
ENetProtocolCommandHeader header;
enet_uint16 dataLength;
-} ENetProtocolSendReliable;
+} ENET_PACKED ENetProtocolSendReliable;
-typedef struct
+typedef struct _ENetProtocolSendUnreliable
{
ENetProtocolCommandHeader header;
enet_uint16 unreliableSequenceNumber;
enet_uint16 dataLength;
-} ENetProtocolSendUnreliable;
+} ENET_PACKED ENetProtocolSendUnreliable;
-typedef struct
+typedef struct _ENetProtocolSendUnsequenced
{
ENetProtocolCommandHeader header;
enet_uint16 unsequencedGroup;
enet_uint16 dataLength;
-} ENetProtocolSendUnsequenced;
+} ENET_PACKED ENetProtocolSendUnsequenced;
-typedef struct
+typedef struct _ENetProtocolSendFragment
{
ENetProtocolCommandHeader header;
enet_uint16 startSequenceNumber;
@@ -152,9 +161,9 @@ typedef struct
enet_uint32 fragmentNumber;
enet_uint32 totalLength;
enet_uint32 fragmentOffset;
-} ENetProtocolSendFragment;
+} ENET_PACKED ENetProtocolSendFragment;
-typedef union
+typedef union _ENetProtocol
{
ENetProtocolCommandHeader header;
ENetProtocolAcknowledge acknowledge;
@@ -168,7 +177,11 @@ typedef union
ENetProtocolSendFragment sendFragment;
ENetProtocolBandwidthLimit bandwidthLimit;
ENetProtocolThrottleConfigure throttleConfigure;
-} ENetProtocol;
+} ENET_PACKED ENetProtocol;
+
+#ifdef _MSC_VER_
+#pragma pack(pop)
+#endif
#endif /* __ENET_PROTOCOL_H__ */