Skip to content

Commit

Permalink
LibCore: fix UDP Server receive to trim buffer to actuall bytes recei…
Browse files Browse the repository at this point in the history
…veed
  • Loading branch information
tryfinally authored and awesomekling committed Aug 9, 2020
1 parent d9470bd commit 043d548
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Libraries/LibCore/UDPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 043d548

Please sign in to comment.