|
Packit |
b802ec |
/*
|
|
Packit |
b802ec |
mtr -- a network diagnostic tool
|
|
Packit |
b802ec |
Copyright (C) 2016 Matt Kimball
|
|
Packit |
b802ec |
|
|
Packit |
b802ec |
This program is free software; you can redistribute it and/or modify
|
|
Packit |
b802ec |
it under the terms of the GNU General Public License version 2 as
|
|
Packit |
b802ec |
published by the Free Software Foundation.
|
|
Packit |
b802ec |
|
|
Packit |
b802ec |
This program is distributed in the hope that it will be useful,
|
|
Packit |
b802ec |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
b802ec |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
b802ec |
GNU General Public License for more details.
|
|
Packit |
b802ec |
|
|
Packit |
b802ec |
You should have received a copy of the GNU General Public License
|
|
Packit |
b802ec |
along with this program; if not, write to the Free Software
|
|
Packit |
b802ec |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
Packit |
b802ec |
*/
|
|
Packit |
b802ec |
|
|
Packit |
b802ec |
#include "wait.h"
|
|
Packit |
b802ec |
|
|
Packit |
b802ec |
#include <io.h>
|
|
Packit |
b802ec |
#include <stdio.h>
|
|
Packit |
b802ec |
#include <windows.h>
|
|
Packit |
b802ec |
|
|
Packit |
b802ec |
#include "command.h"
|
|
Packit |
b802ec |
|
|
Packit |
b802ec |
/*
|
|
Packit |
b802ec |
Sleep until we receive a new probe response, a new command on the
|
|
Packit |
b802ec |
command stream, or a probe timeout. On Windows, this means that
|
|
Packit |
b802ec |
we will sleep with an alertable wait, as all of these conditions
|
|
Packit |
b802ec |
use I/O completion routines as notifications of these events.
|
|
Packit |
b802ec |
*/
|
|
Packit |
b802ec |
void wait_for_activity(
|
|
Packit |
b802ec |
struct command_buffer_t *command_buffer,
|
|
Packit |
b802ec |
struct net_state_t *net_state)
|
|
Packit |
b802ec |
{
|
|
Packit |
b802ec |
DWORD wait_result;
|
|
Packit |
b802ec |
|
|
Packit |
b802ec |
/*
|
|
Packit |
b802ec |
Start the command read overlapped I/O just prior to sleeping.
|
|
Packit |
b802ec |
During development of the Cygwin port, there was a bug where the
|
|
Packit |
b802ec |
overlapped I/O was started earlier in the mtr-packet loop, and
|
|
Packit |
b802ec |
an intermediate alertable wait could leave us in this Sleep
|
|
Packit |
b802ec |
without an active command read. So now we do this here, instead.
|
|
Packit |
b802ec |
*/
|
|
Packit |
b802ec |
start_read_command(command_buffer);
|
|
Packit |
b802ec |
|
|
Packit |
b802ec |
/* Sleep until an I/O completion routine runs */
|
|
Packit |
b802ec |
wait_result = SleepEx(INFINITE, TRUE);
|
|
Packit |
b802ec |
|
|
Packit |
b802ec |
if (wait_result == WAIT_FAILED) {
|
|
Packit |
b802ec |
fprintf(stderr, "SleepEx failure %d\n", GetLastError());
|
|
Packit |
b802ec |
exit(EXIT_FAILURE);
|
|
Packit |
b802ec |
}
|
|
Packit |
b802ec |
}
|