equal
deleted
inserted
replaced
4 |
4 |
5 #include "../../stdafx.h" |
5 #include "../../stdafx.h" |
6 #include "../../macros.h" |
6 #include "../../macros.h" |
7 #include "../../string.h" |
7 #include "../../string.h" |
8 |
8 |
9 #include "os_abstraction.h" |
|
10 #include "config.h" |
|
11 #include "packet.h" |
9 #include "packet.h" |
12 |
10 |
13 /** |
11 /** |
14 * @file packet.h Basic functions to create, fill and read packets. |
12 * @file packet.h Basic functions to create, fill and read packets. |
15 */ |
13 */ |
22 /** |
20 /** |
23 * Create a packet for sending |
21 * Create a packet for sending |
24 * @param type the of packet |
22 * @param type the of packet |
25 * @return the newly created packet |
23 * @return the newly created packet |
26 */ |
24 */ |
27 Packet *NetworkSend_Init(PacketType type) |
25 Packet *NetworkSend_Init(const PacketType type) |
28 { |
26 { |
29 Packet *packet = malloc(sizeof(Packet)); |
27 Packet *packet = malloc(sizeof(Packet)); |
30 /* An error is inplace here, because it simply means we ran out of memory. */ |
28 /* An error is inplace here, because it simply means we ran out of memory. */ |
31 if (packet == NULL) error("Failed to allocate Packet"); |
29 if (packet == NULL) error("Failed to allocate Packet"); |
32 |
30 |
112 |
110 |
113 |
111 |
114 extern uint CloseConnection(NetworkClientState *cs); |
112 extern uint CloseConnection(NetworkClientState *cs); |
115 |
113 |
116 /** Is it safe to read from the packet, i.e. didn't we run over the buffer ? */ |
114 /** Is it safe to read from the packet, i.e. didn't we run over the buffer ? */ |
117 static inline bool CanReadFromPacket(NetworkClientState *cs, Packet *packet, uint bytes_to_read) |
115 static inline bool CanReadFromPacket(NetworkClientState *cs, const Packet *packet, const uint bytes_to_read) |
118 { |
116 { |
119 /* Don't allow reading from a closed socket */ |
117 /* Don't allow reading from a closed socket */ |
120 if (HasClientQuit(cs)) return false; |
118 if (HasClientQuit(cs)) return false; |
121 |
119 |
122 /* Check if variable is within packet-size */ |
120 /* Check if variable is within packet-size */ |