mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-11-06 13:30:00 +00:00
Merge pull request #9625 from rooklz/fix/macos-shutdown-already-shut
fix(libkernel): treat a socket direction that is already shut as shut on macOS hosts
This commit is contained in:
1 file changed
+20
-1
@@ -1377,11 +1377,30 @@ int APS5_VABI bind_nid_postfix(int descriptor, const void* address, std::uint32_
|
||||
if (!Address(socket->family, address, mapped ? 28 : length, native, size)) return -1;
|
||||
return ::bind(socket->value, reinterpret_cast<sockaddr*>(&native), size) ? Fail(NativeError()) : 0;
|
||||
}
|
||||
namespace {
|
||||
bool AlreadyShut(NativeSocket socket, int how) {
|
||||
#ifdef __APPLE__
|
||||
if (errno != ENOTCONN) return false;
|
||||
sockaddr_storage peer{};
|
||||
socklen_t size = sizeof(peer);
|
||||
if (::getpeername(socket, reinterpret_cast<sockaddr*>(&peer), &size)) {
|
||||
errno = ENOTCONN;
|
||||
return false;
|
||||
}
|
||||
return how != SHUT_RDWR || ::shutdown(socket, SHUT_WR) == 0 || errno == ENOTCONN;
|
||||
#else
|
||||
(void)socket;
|
||||
(void)how;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int APS5_VABI shutdown_nid_postfix(int descriptor, int how) {
|
||||
const auto socket = Lookup(descriptor);
|
||||
if (!socket) return -1;
|
||||
if (how < 0 || how > 2) return Fail(22);
|
||||
if (::shutdown(socket->value, how)) return Fail(NativeError());
|
||||
if (::shutdown(socket->value, how) && !AlreadyShut(socket->value, how)) return Fail(NativeError());
|
||||
std::lock_guard lock(socket->modeMutex);
|
||||
if (how != 1) socket->receiveShut = true;
|
||||
if (how != 0) socket->sendShut = true;
|
||||
|
||||
Reference in new issue
Block a user