Skip to content

Commit

Permalink
PINE: Fix crash on exit (#13409)
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 authored Feb 20, 2023
1 parent bb2c919 commit 3922f76
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 3rdparty/pine/pine_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define close_portable(a) (close(a))
#include <sys/socket.h>
#include <sys/un.h>
#include <poll.h>
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
#include <unistd.h>
#endif
Expand Down Expand Up @@ -354,6 +355,28 @@ namespace pine
*/
bool StartSocket()
{
::pollfd poll_fd{};

for (int pending_connection = 0; pending_connection != 1;)
{
if (thread_ctrl::state() == thread_state::aborting)
{
return false;
}

std::memset(&poll_fd, 0, sizeof(poll_fd));
poll_fd.events = POLLIN;
poll_fd.revents = 0;
poll_fd.fd = m_sock;

#ifdef _WIN32
// Try to wait for an incoming connection
pending_connection = ::WSAPoll(&poll_fd, 1, 10);
#else
pending_connection = ::poll(&poll_fd, 1, 10);
#endif
}

m_msgsock = accept(m_sock, 0, 0);

if (m_msgsock == -1)
Expand Down

0 comments on commit 3922f76

Please sign in to comment.