1: /*
2: mtr -- a network diagnostic tool
3: Copyright (C) 2016 Matt Kimball
4:
5: This program is free software; you can redistribute it and/or modify
6: it under the terms of the GNU General Public License version 2 as
7: published by the Free Software Foundation.
8:
9: This program is distributed in the hope that it will be useful,
10: but WITHOUT ANY WARRANTY; without even the implied warranty of
11: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: GNU General Public License for more details.
13:
14: You should have received a copy of the GNU General Public License along
15: with this program; if not, write to the Free Software Foundation, Inc.,
16: 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17: */
18:
19: #include "wait.h"
20:
21: #include <error.h>
22: #include <errno.h>
23: #include <sys/select.h>
24:
25: #include "command.h"
26:
27: /*
28: Wait for either a request from the command stream or
29: for the probe results to be passed from the ICMP service
30: thread.
31: */
32: void wait_for_activity(
33: struct command_buffer_t *command_buffer,
34: struct net_state_t *net_state)
35: {
36: int nfds;
37: fd_set read_set;
38: int ready_count;
39:
40: FD_ZERO(&read_set);
41:
42: FD_SET(command_buffer->command_stream, &read_set);
43: nfds = command_buffer->command_stream + 1;
44:
45: FD_SET(net_state->platform.thread_out_pipe_read, &read_set);
46: if (net_state->platform.thread_out_pipe_read >= nfds) {
47: nfds = net_state->platform.thread_out_pipe_read + 1;
48: }
49:
50: while (true) {
51: ready_count =
52: select(nfds, &read_set, NULL, NULL, NULL);
53:
54: if (ready_count != -1) {
55: return;
56: }
57:
58: /*
59: EINTR and EAGAIN simply mean that the select should
60: be retried.
61: */
62: if (errno != EINTR && errno != EAGAIN) {
63: error(EXIT_FAILURE, errno, "unexpected select error");
64: }
65: }
66: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>