Skip to content

Commit bd8b5d4

Browse files
committed
net: add more details to log information in ETE and WakeupPipes
1 parent ec99294 commit bd8b5d4

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/util/edge.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ EdgeTriggeredEvents::EdgeTriggeredEvents(SocketEventsMode events_mode)
2222
#ifdef USE_EPOLL
2323
m_fd = epoll_create1(0);
2424
if (m_fd == -1) {
25-
LogPrintf("Unable to initialize EdgeTriggeredEvents, epoll_create1 returned -1\n");
25+
LogPrintf("Unable to initialize EdgeTriggeredEvents, epoll_create1 returned -1 with error %s\n",
26+
NetworkErrorString(WSAGetLastError()));
2627
return;
2728
}
2829
#else
@@ -33,7 +34,8 @@ EdgeTriggeredEvents::EdgeTriggeredEvents(SocketEventsMode events_mode)
3334
#ifdef USE_KQUEUE
3435
m_fd = kqueue();
3536
if (m_fd == -1) {
36-
LogPrintf("Unable to initialize EdgeTriggeredEvents, kqueue returned -1\n");
37+
LogPrintf("Unable to initialize EdgeTriggeredEvents, kqueue returned -1 with error %s\n",
38+
NetworkErrorString(WSAGetLastError()));
3739
return;
3840
}
3941
#else

src/util/wpipe.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,28 @@
88
#include <util/edge.h>
99
#include <util/sock.h>
1010

11+
static constexpr int EXPECTED_PIPE_WRITTEN_BYTES = 1;
12+
1113
WakeupPipe::WakeupPipe(EdgeTriggeredEvents* edge_trig_events)
1214
: m_edge_trig_events{edge_trig_events}
1315
{
1416
#ifdef USE_WAKEUP_PIPE
1517
if (pipe(m_pipe.data()) != 0) {
16-
LogPrintf("Unable to initialize WakeupPipe, pipe() for m_pipe failed\n");
18+
LogPrintf("Unable to initialize WakeupPipe, pipe() for m_pipe failed with error %s\n",
19+
NetworkErrorString(WSAGetLastError()));
1720
return;
1821
}
1922
for (size_t idx = 0; idx < m_pipe.size(); idx++) {
2023
int flags = fcntl(m_pipe[idx], F_GETFL, 0);
2124
if (fcntl(m_pipe[idx], F_SETFL, flags | O_NONBLOCK) == -1) {
22-
LogPrintf("Unable to initialize WakeupPipe, fcntl for O_NONBLOCK on m_pipe[%d] failed\n", idx);
25+
LogPrintf("Unable to initialize WakeupPipe, fcntl for O_NONBLOCK on m_pipe[%d] failed with error %s\n", idx,
26+
NetworkErrorString(WSAGetLastError()));
2327
return;
2428
}
2529
}
2630
if (edge_trig_events && !edge_trig_events->RegisterPipe(m_pipe[0])) {
27-
LogPrintf("Unable to initialize WakeupPipe, EdgeTriggeredEvents::RegisterPipe() failed\n");
31+
LogPrintf("Unable to initialize WakeupPipe, EdgeTriggeredEvents::RegisterPipe() failed for m_pipe[0] = %d\n",
32+
m_pipe[0]);
2833
return;
2934
}
3035
m_valid = true;
@@ -38,7 +43,8 @@ WakeupPipe::~WakeupPipe()
3843
if (m_valid) {
3944
#ifdef USE_WAKEUP_PIPE
4045
if (m_edge_trig_events && !m_edge_trig_events->UnregisterPipe(m_pipe[0])) {
41-
LogPrintf("Destroying WakeupPipe instance, EdgeTriggeredEvents::UnregisterPipe() failed\n");
46+
LogPrintf("Destroying WakeupPipe instance, EdgeTriggeredEvents::UnregisterPipe() failed for m_pipe[0] = %d\n",
47+
m_pipe[0]);
4248
}
4349
for (size_t idx = 0; idx < m_pipe.size(); idx++) {
4450
if (close(m_pipe[idx]) != 0) {
@@ -72,9 +78,14 @@ void WakeupPipe::Write()
7278
#ifdef USE_WAKEUP_PIPE
7379
assert(m_valid && m_pipe[1] != -1);
7480

75-
std::array<uint8_t, 1> buf;
76-
if (write(m_pipe[1], buf.data(), buf.size()) != 1) {
77-
LogPrintf("Write to m_pipe[1] failed\n");
81+
std::array<uint8_t, EXPECTED_PIPE_WRITTEN_BYTES> buf;
82+
int ret = write(m_pipe[1], buf.data(), buf.size());
83+
if (ret == -1) {
84+
LogPrintf("write() to m_pipe[1] = %d failed with error %s\n", m_pipe[1], NetworkErrorString(WSAGetLastError()));
85+
}
86+
if (ret != EXPECTED_PIPE_WRITTEN_BYTES) {
87+
LogPrintf("write() to m_pipe[1] = %d succeeded with unexpected result %d (expected %d)\n", m_pipe[1], ret,
88+
EXPECTED_PIPE_WRITTEN_BYTES);
7889
}
7990

8091
m_need_wakeup = false;

0 commit comments

Comments
 (0)