Repository navigation
Conversation
With MSG_TRUNC, recv() and recvfrom() can return the real length of the datagram, which may be larger than the requested size. Since PyBytesWriter_FinishWithSize() now rejects a size larger than the allocated one, this raised ValueError after the datagram had already been consumed. Return only the bytes actually received instead.
|
It seems like only recv() and recvfrom() should be fixed: recvmsg() ignores MSG_TRUNC flag, but it can set MSG_TRUNC flag in the returned flags. |
Documentation build overview
|
|
@ViderStar: Next time, please ask the issue reporter (@kolyshkin) if they want to work on a pull request, rather than directly propose your PR. @ViderStar: I pushed directly to your branch since I wanted to change multiple times. Can you please review the updated PR and tells me if you look good to you? @kolyshkin: Can you also please review and test the change? I modified the recv() and recvfrom() documentation to document MSG_TRUNC flag. In practice with this change, the flag is basically ignored. But instead, I tried to describe the behavior, since the flag is not technically ignored. |
|
Ah, and I also added a test on |
With
MSG_TRUNC, Linuxrecv(2)/recvfrom(2)return the real length of the datagram, which can be larger than the buffer. Since gh-157226,PyBytesWriter_FinishWithSize()rejects a size larger than the allocated one, sosock.recv(n, MSG_TRUNC)andsock.recvfrom(n, MSG_TRUNC)raiseValueErrorafter the datagram has already been consumed.This clamps the returned length to the requested size, so only the bytes actually received are returned (as suggested in gh-69121).
recv_into()andrecvfrom_into()are unchanged: they still return the value from the system call as is, which is the way to get the full datagram length.Tests: added
testRecvTruncandtestRecvFromTrunctoBasicUDPTest. On a Linux debug build they fail onmainwithValueError: size larger than allocated sizeand pass with this change; fulltest_socketpasses on Linux and macOS.