equal
deleted
inserted
replaced
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 * |
18 * |
19 * Author: Tom Goff <thomas.goff@boeing.com> |
19 * Author: Tom Goff <thomas.goff@boeing.com> |
20 */ |
20 */ |
21 |
21 |
22 #include <errno.h> |
22 #include <cerrno> |
23 #include <string.h> |
23 #include <cstring> |
24 #include <unistd.h> |
24 #include <unistd.h> |
25 #include <fcntl.h> |
25 #include <fcntl.h> |
26 |
26 |
27 #include "log.h" |
27 #include "log.h" |
28 #include "fatal-error.h" |
28 #include "fatal-error.h" |
57 |
57 |
58 // create a pipe for inter-thread event notification |
58 // create a pipe for inter-thread event notification |
59 tmp = pipe (m_evpipe); |
59 tmp = pipe (m_evpipe); |
60 if (tmp == -1) |
60 if (tmp == -1) |
61 { |
61 { |
62 NS_FATAL_ERROR ("pipe() failed: " << strerror (errno)); |
62 NS_FATAL_ERROR ("pipe() failed: " << std::strerror (errno)); |
63 } |
63 } |
64 |
64 |
65 // make the read end non-blocking |
65 // make the read end non-blocking |
66 tmp = fcntl (m_evpipe[0], F_GETFL); |
66 tmp = fcntl (m_evpipe[0], F_GETFL); |
67 if (tmp == -1) |
67 if (tmp == -1) |
68 { |
68 { |
69 NS_FATAL_ERROR ("fcntl() failed: " << strerror (errno)); |
69 NS_FATAL_ERROR ("fcntl() failed: " << std::strerror (errno)); |
70 } |
70 } |
71 if (fcntl (m_evpipe[0], F_SETFL, tmp | O_NONBLOCK) == -1) |
71 if (fcntl (m_evpipe[0], F_SETFL, tmp | O_NONBLOCK) == -1) |
72 { |
72 { |
73 NS_FATAL_ERROR ("fcntl() failed: " << strerror (errno)); |
73 NS_FATAL_ERROR ("fcntl() failed: " << std::strerror (errno)); |
74 } |
74 } |
75 |
75 |
76 m_fd = fd; |
76 m_fd = fd; |
77 m_readCallback = readCallback; |
77 m_readCallback = readCallback; |
78 |
78 |
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(): " << std::strerror (errno)); |
120 } |
120 } |
121 |
121 |
122 // join the read thread |
122 // join the read thread |
123 if (m_readThread != 0) |
123 if (m_readThread != 0) |
124 { |
124 { |
164 fd_set readfds = rfds; |
164 fd_set readfds = rfds; |
165 |
165 |
166 r = select (nfds, &readfds, NULL, NULL, NULL); |
166 r = select (nfds, &readfds, NULL, NULL, NULL); |
167 if (r == -1 && errno != EINTR) |
167 if (r == -1 && errno != EINTR) |
168 { |
168 { |
169 NS_FATAL_ERROR ("select() failed: " << strerror (errno)); |
169 NS_FATAL_ERROR ("select() failed: " << std::strerror (errno)); |
170 } |
170 } |
171 |
171 |
172 if (FD_ISSET (m_evpipe[0], &readfds)) |
172 if (FD_ISSET (m_evpipe[0], &readfds)) |
173 { |
173 { |
174 // drain the event pipe |
174 // drain the event pipe |
186 { |
186 { |
187 break; |
187 break; |
188 } |
188 } |
189 else |
189 else |
190 { |
190 { |
191 NS_FATAL_ERROR ("read() failed: " << strerror (errno)); |
191 NS_FATAL_ERROR ("read() failed: " << std::strerror (errno)); |
192 } |
192 } |
193 } |
193 } |
194 } |
194 } |
195 } |
195 } |
196 |
196 |