PINE: Fix crash on exit (#13409)

This commit is contained in:
Elad Ashkenazi 2023-02-20 10:59:40 +02:00 committed by GitHub
parent bb2c9196f5
commit 3922f76ab5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,6 +24,7 @@
#define close_portable(a) (close(a)) #define close_portable(a) (close(a))
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h> #include <sys/un.h>
#include <poll.h>
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -354,6 +355,28 @@ namespace pine
*/ */
bool StartSocket() 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); m_msgsock = accept(m_sock, 0, 0);
if (m_msgsock == -1) if (m_msgsock == -1)