Skip to content

Commit 3df128d

Browse files
chaoticgdF0bes
authored andcommitted
PINE: Ignore SIGPIPE properly on macOS
1 parent 426d77a commit 3df128d

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

pcsx2/PINE.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -384,32 +384,32 @@ std::vector<u8>& PINEServer::MakeFailIPC(std::vector<u8>& ret_buffer, uint32_t s
384384
bool PINEServer::AcceptClient()
385385
{
386386
s_msgsock = accept(s_sock, 0, 0);
387-
if (s_msgsock >= 0)
387+
if (s_msgsock < 0)
388388
{
389-
// Gross C-style cast, but SOCKET is a handle on Windows.
390-
Console.WriteLn("PINE: New client with FD %d connected.", (int)s_msgsock);
391-
return true;
389+
// everything else is non recoverable in our scope
390+
// we also mark as recoverable socket errors where it would block a
391+
// non blocking socket, even though our socket is blocking, in case
392+
// we ever have to implement a non blocking socket.
393+
#ifdef _WIN32
394+
const int errno_w = WSAGetLastError();
395+
if (!(errno_w == WSAECONNRESET || errno_w == WSAEINTR || errno_w == WSAEINPROGRESS || errno_w == WSAEMFILE || errno_w == WSAEWOULDBLOCK) && s_sock != INVALID_SOCKET)
396+
Console.Error("PINE: accept() returned error %d", errno_w);
397+
#else
398+
if (!(errno == ECONNABORTED || errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) && s_sock >= 0)
399+
Console.Error("PINE: accept() returned error %d", errno);
400+
#endif
401+
402+
return false;
392403
}
393404

394405
#ifdef __APPLE__
395406
int nosigpipe = 1;
396407
setsockopt(s_msgsock, SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe, sizeof(nosigpipe));
397408
#endif
398409

399-
// everything else is non recoverable in our scope
400-
// we also mark as recoverable socket errors where it would block a
401-
// non blocking socket, even though our socket is blocking, in case
402-
// we ever have to implement a non blocking socket.
403-
#ifdef _WIN32
404-
const int errno_w = WSAGetLastError();
405-
if (!(errno_w == WSAECONNRESET || errno_w == WSAEINTR || errno_w == WSAEINPROGRESS || errno_w == WSAEMFILE || errno_w == WSAEWOULDBLOCK) && s_sock != INVALID_SOCKET)
406-
Console.Error("PINE: accept() returned error %d", errno_w);
407-
#else
408-
if (!(errno == ECONNABORTED || errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) && s_sock >= 0)
409-
Console.Error("PINE: accept() returned error %d", errno);
410-
#endif
411-
412-
return false;
410+
// Gross C-style cast, but SOCKET is a handle on Windows.
411+
Console.WriteLn("PINE: New client with FD %d connected.", (int)s_msgsock);
412+
return true;
413413
}
414414

415415
void PINEServer::MainLoop()

0 commit comments

Comments
 (0)