8
8
#include < util/edge.h>
9
9
#include < util/sock.h>
10
10
11
+ static constexpr int EXPECTED_PIPE_WRITTEN_BYTES = 1 ;
12
+
11
13
WakeupPipe::WakeupPipe (EdgeTriggeredEvents* edge_trig_events)
12
14
: m_edge_trig_events{edge_trig_events}
13
15
{
14
16
#ifdef USE_WAKEUP_PIPE
15
17
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 ()));
17
20
return ;
18
21
}
19
22
for (size_t idx = 0 ; idx < m_pipe.size (); idx++) {
20
23
int flags = fcntl (m_pipe[idx], F_GETFL, 0 );
21
24
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 ()));
23
27
return ;
24
28
}
25
29
}
26
30
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 ]);
28
33
return ;
29
34
}
30
35
m_valid = true ;
@@ -38,7 +43,8 @@ WakeupPipe::~WakeupPipe()
38
43
if (m_valid) {
39
44
#ifdef USE_WAKEUP_PIPE
40
45
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 ]);
42
48
}
43
49
for (size_t idx = 0 ; idx < m_pipe.size (); idx++) {
44
50
if (close (m_pipe[idx]) != 0 ) {
@@ -72,9 +78,14 @@ void WakeupPipe::Write()
72
78
#ifdef USE_WAKEUP_PIPE
73
79
assert (m_valid && m_pipe[1 ] != -1 );
74
80
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);
78
89
}
79
90
80
91
m_need_wakeup = false ;
0 commit comments