diff options
author | Rubidium <rubidium@openttd.org> | 2021-04-18 12:36:19 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-04-24 20:42:01 +0200 |
commit | 75386873b77df4f3493edd5bbba92b33007bdd21 (patch) | |
tree | 5a1eb4171df2c501083104103eb060a79b0791f5 /src/network/core/packet.h | |
parent | 450178d780eb885717c53a2dad62587332efc0f4 (diff) | |
download | openttd-75386873b77df4f3493edd5bbba92b33007bdd21.tar.xz |
Codechange: use std::vector instead of a fixed size array for Packets
Diffstat (limited to 'src/network/core/packet.h')
-rw-r--r-- | src/network/core/packet.h | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/network/core/packet.h b/src/network/core/packet.h index 1a9c9faea..1ac7f18a1 100644 --- a/src/network/core/packet.h +++ b/src/network/core/packet.h @@ -43,23 +43,17 @@ struct Packet { private: /** The next packet. Used for queueing packets before sending. */ Packet *next; - /** - * The size of the whole packet for received packets. For packets - * that will be sent, the value is filled in just before the - * actual transmission. - */ - PacketSize size; /** The current read/write position in the packet */ PacketSize pos; - /** The buffer of this packet, of basically variable length up to SEND_MTU. */ - byte *buffer; + /** The buffer of this packet. */ + std::vector<byte> buffer; + /** Socket we're associated with. */ NetworkSocketHandler *cs; public: Packet(NetworkSocketHandler *cs, size_t initial_read_size = sizeof(PacketSize)); Packet(PacketType type); - ~Packet(); static void AddToQueue(Packet **queue, Packet *packet); static Packet *PopFromQueue(Packet **queue); @@ -118,7 +112,7 @@ public: assert(this->pos < this->buffer.size()); assert(this->pos + amount <= this->buffer.size()); /* Making buffer a char means casting a lot in the Recv/Send functions. */ - const char *output_buffer = reinterpret_cast<const char*>(this->buffer + this->pos); + const char *output_buffer = reinterpret_cast<const char*>(this->buffer.data() + this->pos); ssize_t bytes = transfer_function(destination, output_buffer, static_cast<A>(amount), std::forward<Args>(args)...); if (bytes > 0) this->pos += bytes; return bytes; @@ -183,7 +177,7 @@ public: assert(this->pos < this->buffer.size()); assert(this->pos + amount <= this->buffer.size()); /* Making buffer a char means casting a lot in the Recv/Send functions. */ - char *input_buffer = reinterpret_cast<char*>(this->buffer + this->pos); + char *input_buffer = reinterpret_cast<char*>(this->buffer.data() + this->pos); ssize_t bytes = transfer_function(source, input_buffer, static_cast<A>(amount), std::forward<Args>(args)...); if (bytes > 0) this->pos += bytes; return bytes; |