Merge pull request #515 from msekletar/icmp-socket-leak
[mtr.git] / packet / wait_cygwin.c
blob0546231527704b082175c5a3aae024535a21bb5b
1 /*
2 mtr -- a network diagnostic tool
3 Copyright (C) 2016 Matt Kimball
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.
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.
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.
19 #include "wait.h"
21 #include <error.h>
22 #include <errno.h>
23 #include <sys/select.h>
25 #include "command.h"
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.
32 void wait_for_activity(
33 struct command_buffer_t *command_buffer,
34 struct net_state_t *net_state)
36 int nfds;
37 fd_set read_set;
38 int ready_count;
40 FD_ZERO(&read_set);
42 FD_SET(command_buffer->command_stream, &read_set);
43 nfds = command_buffer->command_stream + 1;
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;
50 while (true) {
51 ready_count =
52 select(nfds, &read_set, NULL, NULL, NULL);
54 if (ready_count != -1) {
55 return;
59 EINTR and EAGAIN simply mean that the select should
60 be retried.
62 if (errno != EINTR && errno != EAGAIN) {
63 error(EXIT_FAILURE, errno, "unexpected select error");