|
|
| 110 |
{ |
110 |
{ |
| 111 |
m_stop = true; |
111 |
m_stop = true; |
| 112 |
|
112 |
|
| 113 |
// signal the read thread and close the write end of the event pipe |
113 |
// signal the read thread |
| 114 |
if (m_evpipe[1] != -1) |
114 |
if (m_evpipe[1] != -1) |
| 115 |
{ |
115 |
{ |
| 116 |
char zero = 0; |
116 |
char zero = 0; |
| 117 |
ssize_t len = write (m_evpipe[1], &zero, sizeof (zero)); |
117 |
ssize_t len = write (m_evpipe[1], &zero, sizeof (zero)); |
| 118 |
if (len != sizeof (zero)) |
118 |
if (len != sizeof (zero)) |
| 119 |
NS_LOG_WARN ("incomplete write(): " << strerror (errno)); |
119 |
NS_LOG_WARN ("incomplete write(): " << strerror (errno)); |
| 120 |
close (m_evpipe[1]); |
|
|
| 121 |
m_evpipe[1] = -1; |
| 122 |
} |
120 |
} |
| 123 |
|
121 |
|
| 124 |
// join the read thread |
122 |
// join the read thread |
|
|
| 128 |
m_readThread = 0; |
126 |
m_readThread = 0; |
| 129 |
} |
127 |
} |
| 130 |
|
128 |
|
|
|
129 |
// close the write end of the event pipe |
| 130 |
if (m_evpipe[1] != -1) |
| 131 |
{ |
| 132 |
close (m_evpipe[1]); |
| 133 |
m_evpipe[1] = -1; |
| 134 |
} |
| 135 |
|
| 131 |
// close the read end of the event pipe |
136 |
// close the read end of the event pipe |
| 132 |
if (m_evpipe[0] != -1) |
137 |
if (m_evpipe[0] != -1) |
| 133 |
{ |
138 |
{ |
|
|
| 167 |
if (FD_ISSET (m_evpipe[0], &readfds)) |
172 |
if (FD_ISSET (m_evpipe[0], &readfds)) |
| 168 |
{ |
173 |
{ |
| 169 |
// drain the event pipe |
174 |
// drain the event pipe |
| 170 |
ssize_t len; |
|
|
| 171 |
for (;;) |
175 |
for (;;) |
| 172 |
{ |
176 |
{ |
| 173 |
char buf[1024]; |
177 |
char buf[1024]; |
| 174 |
len = read (m_evpipe[0], buf, sizeof (buf)); |
178 |
ssize_t len = read (m_evpipe[0], buf, sizeof (buf)); |
| 175 |
if (len == 0) |
179 |
if (len == 0) |
| 176 |
{ |
180 |
{ |
| 177 |
NS_FATAL_ERROR ("event pipe closed"); |
181 |
NS_FATAL_ERROR ("event pipe closed"); |
| 178 |
} |
182 |
} |
| 179 |
if (len < 0) |
183 |
if (len < 0) |
| 180 |
{ |
184 |
{ |
| 181 |
break; |
185 |
if (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK) |
|
|
186 |
{ |
| 187 |
break; |
| 188 |
} |
| 189 |
else |
| 190 |
{ |
| 191 |
NS_FATAL_ERROR ("read() failed: " << strerror (errno)); |
| 192 |
} |
| 182 |
} |
193 |
} |
| 183 |
} |
194 |
} |
| 184 |
|
|
|
| 185 |
if (len < 0 && errno != EAGAIN && errno != EWOULDBLOCK) |
| 186 |
{ |
| 187 |
NS_LOG_WARN ("read() failed: " << strerror (errno)); |
| 188 |
break; |
| 189 |
} |
| 190 |
} |
195 |
} |
| 191 |
|
196 |
|
| 192 |
if (m_stop) |
197 |
if (m_stop) |