Skip to content

Commit

Permalink
net: add more details to log information in ETE and WakeupPipes
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed May 9, 2024
1 parent 1d96a76 commit d5f0838
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/util/edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
25 changes: 18 additions & 7 deletions src/util/wpipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,28 @@
#include <logging.h>
#include <util/edge.h>

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;
Expand All @@ -37,7 +42,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) {
Expand Down Expand Up @@ -71,9 +77,14 @@ void WakeupPipe::Write()
#ifdef USE_WAKEUP_PIPE
assert(m_valid && m_pipe[1] != -1);

std::array<uint8_t, 1> buf;
if (write(m_pipe[1], buf.data(), buf.size()) != 1) {
LogPrintf("Write to m_pipe[1] failed\n");
std::array<uint8_t, EXPECTED_PIPE_WRITTEN_BYTES> 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;
Expand Down

0 comments on commit d5f0838

Please sign in to comment.