summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2020-07-30 01:38:19 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2020-07-30 01:38:19 +0200
commit1f49e7e4350298dad2e0a6e340b608a80a625e4b (patch)
treea75142de2c9500a4136b101a2dcd4527b0733f45 /src
parentMinor protocol support improvement (diff)
downloadAltCraft-1f49e7e4350298dad2e0a6e340b608a80a625e4b.tar
AltCraft-1f49e7e4350298dad2e0a6e340b608a80a625e4b.tar.gz
AltCraft-1f49e7e4350298dad2e0a6e340b608a80a625e4b.tar.bz2
AltCraft-1f49e7e4350298dad2e0a6e340b608a80a625e4b.tar.lz
AltCraft-1f49e7e4350298dad2e0a6e340b608a80a625e4b.tar.xz
AltCraft-1f49e7e4350298dad2e0a6e340b608a80a625e4b.tar.zst
AltCraft-1f49e7e4350298dad2e0a6e340b608a80a625e4b.zip
Diffstat (limited to 'src')
-rw-r--r--src/Network.cpp3
-rw-r--r--src/Stream.cpp9
-rw-r--r--src/Stream.hpp3
3 files changed, 12 insertions, 3 deletions
diff --git a/src/Network.cpp b/src/Network.cpp
index bb92e7f..4280b50 100644
--- a/src/Network.cpp
+++ b/src/Network.cpp
@@ -98,7 +98,8 @@ void Network::SendPacket(Packet &packet, int compressionThreshold) {
stream->WriteVarInt(packetSize.GetCountedSize());
stream->WriteVarInt(packet.GetPacketId());
packet.ToStream(stream.get());
- }
+ }
+ stream->Flush();
}
std::shared_ptr<Packet> Network::ReceivePacketByPacketId(int packetId, ConnectionState state, StreamInput &stream) {
diff --git a/src/Stream.cpp b/src/Stream.cpp
index efe37d2..5c99724 100644
--- a/src/Stream.cpp
+++ b/src/Stream.cpp
@@ -360,9 +360,14 @@ void StreamSocket::ReadData(unsigned char *buffPtr, size_t buffLen) {
}
void StreamSocket::WriteData(unsigned char *buffPtr, size_t buffLen) {
- socket->Write(buffPtr, buffLen);
+ std::copy(buffPtr, buffPtr + buffLen, std::back_inserter(buffer));
}
StreamSocket::StreamSocket(Socket *socketPtr) : socket(socketPtr) {
-} \ No newline at end of file
+}
+
+void StreamSocket::Flush() {
+ socket->Write(buffer.data(), buffer.size());
+ buffer.clear();
+}
diff --git a/src/Stream.hpp b/src/Stream.hpp
index a7c161b..9b6e5ff 100644
--- a/src/Stream.hpp
+++ b/src/Stream.hpp
@@ -100,9 +100,12 @@ public:
class StreamSocket : public StreamInput, public StreamOutput {
Socket *socket;
+ std::vector<unsigned char> buffer;
void ReadData(unsigned char *buffPtr, size_t buffLen) override;
void WriteData(unsigned char *buffPtr, size_t buffLen) override;
public:
StreamSocket(Socket *socketPtr);
~StreamSocket() = default;
+
+ void Flush();
}; \ No newline at end of file