diff --git a/src/util/edge.cpp b/src/util/edge.cpp index 482600c8c0..bb7f867127 100644 --- a/src/util/edge.cpp +++ b/src/util/edge.cpp @@ -22,7 +22,8 @@ EdgeTriggeredEvents::EdgeTriggeredEvents(SocketEventsMode events_mode) #ifdef USE_EPOLL m_fd = epoll_create1(0); if (m_fd == -1) { - LogPrintf("Unable to initialize EdgeTriggeredEvents, epoll_create1 returned -1\n"); + LogPrintf("Unable to initialize EdgeTriggeredEvents, epoll_create1 returned -1 with error %s\n", + NetworkErrorString(WSAGetLastError())); return; } #else @@ -33,7 +34,8 @@ EdgeTriggeredEvents::EdgeTriggeredEvents(SocketEventsMode events_mode) #ifdef USE_KQUEUE m_fd = kqueue(); if (m_fd == -1) { - LogPrintf("Unable to initialize EdgeTriggeredEvents, kqueue returned -1\n"); + LogPrintf("Unable to initialize EdgeTriggeredEvents, kqueue returned -1 with error %s\n", + NetworkErrorString(WSAGetLastError())); return; } #else diff --git a/src/util/wpipe.cpp b/src/util/wpipe.cpp index f4210d6703..732e23c791 100644 --- a/src/util/wpipe.cpp +++ b/src/util/wpipe.cpp @@ -8,23 +8,28 @@ #include #include +static constexpr int EXPECTED_PIPE_WRITTEN_BYTES = 1; + WakeupPipe::WakeupPipe(EdgeTriggeredEvents* edge_trig_events) : m_edge_trig_events{edge_trig_events} { #ifdef USE_WAKEUP_PIPE if (pipe(m_pipe.data()) != 0) { - LogPrintf("Unable to initialize WakeupPipe, pipe() for m_pipe failed\n"); + LogPrintf("Unable to initialize WakeupPipe, pipe() for m_pipe failed with error %s\n", + NetworkErrorString(WSAGetLastError())); return; } for (size_t idx = 0; idx < m_pipe.size(); idx++) { int flags = fcntl(m_pipe[idx], F_GETFL, 0); if (fcntl(m_pipe[idx], F_SETFL, flags | O_NONBLOCK) == -1) { - LogPrintf("Unable to initialize WakeupPipe, fcntl for O_NONBLOCK on m_pipe[%d] failed\n", idx); + LogPrintf("Unable to initialize WakeupPipe, fcntl for O_NONBLOCK on m_pipe[%d] failed with error %s\n", idx, + NetworkErrorString(WSAGetLastError())); return; } } if (edge_trig_events && !edge_trig_events->RegisterPipe(m_pipe[0])) { - LogPrintf("Unable to initialize WakeupPipe, EdgeTriggeredEvents::RegisterPipe() failed\n"); + LogPrintf("Unable to initialize WakeupPipe, EdgeTriggeredEvents::RegisterPipe() failed for m_pipe[0] = %d\n", + m_pipe[0]); return; } m_valid = true; @@ -38,7 +43,8 @@ WakeupPipe::~WakeupPipe() if (m_valid) { #ifdef USE_WAKEUP_PIPE if (m_edge_trig_events && !m_edge_trig_events->UnregisterPipe(m_pipe[0])) { - LogPrintf("Destroying WakeupPipe instance, EdgeTriggeredEvents::UnregisterPipe() failed\n"); + LogPrintf("Destroying WakeupPipe instance, EdgeTriggeredEvents::UnregisterPipe() failed for m_pipe[0] = %d\n", + m_pipe[0]); } for (size_t idx = 0; idx < m_pipe.size(); idx++) { if (close(m_pipe[idx]) != 0) { @@ -72,9 +78,14 @@ void WakeupPipe::Write() #ifdef USE_WAKEUP_PIPE assert(m_valid && m_pipe[1] != -1); - std::array buf; - if (write(m_pipe[1], buf.data(), buf.size()) != 1) { - LogPrintf("Write to m_pipe[1] failed\n"); + std::array buf; + int ret = write(m_pipe[1], buf.data(), buf.size()); + if (ret == -1) { + LogPrintf("write() to m_pipe[1] = %d failed with error %s\n", m_pipe[1], NetworkErrorString(WSAGetLastError())); + } + if (ret != EXPECTED_PIPE_WRITTEN_BYTES) { + LogPrintf("write() to m_pipe[1] = %d succeeded with unexpected result %d (expected %d)\n", m_pipe[1], ret, + EXPECTED_PIPE_WRITTEN_BYTES); } m_need_wakeup = false;