diff options
author | Muhammad Zahalqa <m@tryfinally.com> | 2020-08-08 16:02:28 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-09 21:10:01 +0200 |
commit | 043d548b391147a00986de797a4a57ffb5e58673 (patch) | |
tree | d1bcd5121c007626b9c4984a903b3933b41dc562 | |
parent | d9470bdae763e18291875d1e55dfdc2e608595c0 (diff) | |
download | serenity-043d548b391147a00986de797a4a57ffb5e58673.zip |
LibCore: fix UDP Server receive to trim buffer to actuall bytes receiveed
-rw-r--r-- | Libraries/LibCore/UDPServer.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Libraries/LibCore/UDPServer.cpp b/Libraries/LibCore/UDPServer.cpp index 2b5b466074..6683b956f2 100644 --- a/Libraries/LibCore/UDPServer.cpp +++ b/Libraries/LibCore/UDPServer.cpp @@ -79,13 +79,15 @@ bool UDPServer::bind(const IPv4Address& address, u16 port) ByteBuffer UDPServer::receive(size_t size, sockaddr_in& in) { - auto buf = ByteBuffer::create_zeroed(size); + auto buf = ByteBuffer::create_uninitialized(size); socklen_t in_len = sizeof(in); ssize_t rlen = ::recvfrom(m_fd, buf.data(), size, 0, (sockaddr*)&in, &in_len); if (rlen < 0) { dbg() << "recvfrom: " << strerror(errno); return {}; } + + buf.trim(rlen); return buf; } |