net: add more details to log information in ETE and WakeupPipes

This commit is contained in:
Kittywhiskers Van Gogh 2024-05-04 18:13:50 +00:00
parent ec99294976
commit bd8b5d4007
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
2 changed files with 22 additions and 9 deletions

View File

@ -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

View File

@ -8,23 +8,28 @@
#include <util/edge.h>
#include <util/sock.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;
@ -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<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;