mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-20 10:56:58 +02:00
net: return copied bytes for truncated datagram receives (#510)
Normalize Winsock WSAEMSGSIZE on receive to the copied byte count before converting the peer address. Preserve other receive errors and oversized send failures.
This commit is contained in:
+12
-7
@@ -2025,22 +2025,27 @@ int64_t KYTY_SYSV_ABI Recvfrom(int s, void* buf, uint64_t len, int flags, void*
|
||||
|
||||
const auto host_len = static_cast<SocketIoLength>(
|
||||
std::min<uint64_t>(len, std::numeric_limits<SocketIoLength>::max()));
|
||||
int64_t result = 0;
|
||||
sockaddr_storage host_addr {};
|
||||
SocketLength host_addrlen = sizeof(host_addr);
|
||||
int64_t result = 0;
|
||||
if (addr == nullptr) {
|
||||
result = ::recv(socket, static_cast<char*>(buf), host_len, host_flags);
|
||||
} else {
|
||||
sockaddr_storage host_addr {};
|
||||
SocketLength host_addrlen = sizeof(host_addr);
|
||||
result = ::recvfrom(socket, static_cast<char*>(buf), host_len, host_flags,
|
||||
reinterpret_cast<sockaddr*>(&host_addr), &host_addrlen);
|
||||
if (result >= 0 &&
|
||||
ConvertHostSockaddr(&host_addr, host_addrlen, addr, addrlen) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#if defined(_WIN32)
|
||||
if (result < 0 && WSAGetLastError() == WSAEMSGSIZE) {
|
||||
// Winsock copied the datagram prefix; POSIX reports its length as success.
|
||||
result = host_len;
|
||||
}
|
||||
#endif
|
||||
if (result < 0) {
|
||||
return SetHostSocketError();
|
||||
}
|
||||
if (addr != nullptr && ConvertHostSockaddr(&host_addr, host_addrlen, addr, addrlen) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user