src/network/core/packet.c
changeset 5779 d94be8c0cf86
parent 5778 c1454e0c03bf
equal deleted inserted replaced
5778:c1454e0c03bf 5779:d94be8c0cf86
    20 /**
    20 /**
    21  * Create a packet for sending
    21  * Create a packet for sending
    22  * @param type the of packet
    22  * @param type the of packet
    23  * @return the newly created packet
    23  * @return the newly created packet
    24  */
    24  */
    25 Packet *NetworkSend_Init(PacketType type)
    25 Packet *NetworkSend_Init(const PacketType type)
    26 {
    26 {
    27 	Packet *packet = malloc(sizeof(Packet));
    27 	Packet *packet = malloc(sizeof(Packet));
    28 	/* 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. */
    29 	if (packet == NULL) error("Failed to allocate Packet");
    29 	if (packet == NULL) error("Failed to allocate Packet");
    30 
    30 
   110 
   110 
   111 
   111 
   112 extern uint CloseConnection(NetworkClientState *cs);
   112 extern uint CloseConnection(NetworkClientState *cs);
   113 
   113 
   114 /** 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 ? */
   115 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)
   116 {
   116 {
   117 	/* Don't allow reading from a closed socket */
   117 	/* Don't allow reading from a closed socket */
   118 	if (HasClientQuit(cs)) return false;
   118 	if (HasClientQuit(cs)) return false;
   119 
   119 
   120 	/* Check if variable is within packet-size */
   120 	/* Check if variable is within packet-size */