summaryrefslogtreecommitdiff
path: root/src/network/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/core')
-rw-r--r--src/network/core/packet.cpp15
-rw-r--r--src/network/core/packet.h15
2 files changed, 23 insertions, 7 deletions
diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp
index 6e6bb51c0..c033aec98 100644
--- a/src/network/core/packet.cpp
+++ b/src/network/core/packet.cpp
@@ -175,6 +175,21 @@ void Packet::Send_string(const char *data)
while ((this->buffer[this->size++] = *data++) != '\0') {}
}
+/**
+ * Send as many of the bytes as possible in the packet. This can mean
+ * that it is possible that not all bytes are sent. To cope with this
+ * the function returns the amount of bytes that were actually sent.
+ * @param begin The begin of the buffer to send.
+ * @param end The end of the buffer to send.
+ * @return The number of bytes that were added to this packet.
+ */
+size_t Packet::Send_bytes(const byte *begin, const byte *end)
+{
+ size_t amount = std::min<size_t>(end - begin, SEND_MTU - this->size);
+ memcpy(this->buffer + this->size, begin, amount);
+ this->size += static_cast<PacketSize>(amount);
+ return amount;
+}
/*
* Receiving commands
diff --git a/src/network/core/packet.h b/src/network/core/packet.h
index b091d8a7e..4eb4703c1 100644
--- a/src/network/core/packet.h
+++ b/src/network/core/packet.h
@@ -65,13 +65,14 @@ public:
/* Sending/writing of packets */
void PrepareToSend();
- bool CanWriteToPacket(size_t bytes_to_write);
- void Send_bool (bool data);
- void Send_uint8 (uint8 data);
- void Send_uint16(uint16 data);
- void Send_uint32(uint32 data);
- void Send_uint64(uint64 data);
- void Send_string(const char *data);
+ bool CanWriteToPacket(size_t bytes_to_write);
+ void Send_bool (bool data);
+ void Send_uint8 (uint8 data);
+ void Send_uint16(uint16 data);
+ void Send_uint32(uint32 data);
+ void Send_uint64(uint64 data);
+ void Send_string(const char *data);
+ size_t Send_bytes (const byte *begin, const byte *end);
/* Reading/receiving of packets */
bool HasPacketSizeData() const;