# packet.h

Go to the documentation of this file.

    00001 /* $Id: packet.h 15135 2009-01-18 13:12:57Z rubidium $ */
    00002
    00007 #ifndef NETWORK_CORE_PACKET_H
    00008 #define NETWORK_CORE_PACKET_H
    00009
    00010 #ifdef ENABLE_NETWORK
    00011
    00012 #include "config.h"
    00013 #include "core.h"
    00014
    00015 typedef uint16 PacketSize;
    00016 typedef uint8  PacketType;
    00017
    00027 struct Packet {
    00029   Packet *next;
    00033   PacketSize size;
    00035   PacketSize pos;
    00037   byte buffer[SEND_MTU];
    00038 private:
    00039   NetworkSocketHandler *cs;
    00040
    00041 public:
    00042   Packet(NetworkSocketHandler *cs);
    00043   Packet(PacketType type);
    00044
    00045   /* Sending/writing of packets */
    00046   void PrepareToSend();
    00047
    00048   void Send_bool  (bool   data);
    00049   void Send_uint8 (uint8  data);
    00050   void Send_uint16(uint16 data);
    00051   void Send_uint32(uint32 data);
    00052   void Send_uint64(uint64 data);
    00053   void Send_string(const char *data);
    00054
    00055   /* Reading/receiving of packets */
    00056   void ReadRawPacketSize();
    00057   void PrepareToRead();
    00058
    00059   bool   CanReadFromPacket (uint bytes_to_read);
    00060   bool   Recv_bool  ();
    00061   uint8  Recv_uint8 ();
    00062   uint16 Recv_uint16();
    00063   uint32 Recv_uint32();
    00064   uint64 Recv_uint64();
    00065   void   Recv_string(char *buffer, size_t size, bool allow_newlines = false);
    00066 };
    00067
    00068 Packet *NetworkSend_Init(PacketType type);
    00069
    00070 #endif /* ENABLE_NETWORK */
    00071
    00072 #endif /* NETWORK_CORE_PACKET_H */