diff --git a/posix/subsystem/src/un-socket.cpp b/posix/subsystem/src/un-socket.cpp index 93a4b9952..fe0a854ff 100644 --- a/posix/subsystem/src/un-socket.cpp +++ b/posix/subsystem/src/un-socket.cpp @@ -123,13 +123,14 @@ struct OpenFile : File { // TODO: Truncate packets (for SOCK_DGRAM) here. auto packet = &_recvQueue.front(); - assert(!packet->offset); assert(packet->files.empty()); - auto size = packet->buffer.size(); - assert(max_length >= size); - memcpy(data, packet->buffer.data(), size); - _recvQueue.pop_front(); - co_return size; + + auto chunk = std::min(packet->buffer.size() - packet->offset, max_length); + memcpy(data, packet->buffer.data() + packet->offset, chunk); + packet->offset += chunk; + if(packet->offset == packet->buffer.size()) + _recvQueue.pop_front(); + co_return chunk; } async::result>