aboutsummaryrefslogtreecommitdiffstats
path: root/capture
diff options
context:
space:
mode:
authorTomasz Moń <desowin@gmail.com>2022-07-28 19:20:32 +0200
committerGerald Combs <gerald@wireshark.org>2022-07-28 17:42:11 +0000
commitdf7f3e76b5cd1193cd22b399920e80b9faabfd24 (patch)
tree5c859d780a4b88b5b1cb319a773535a6ac37eb5f /capture
parent0816e317cbef82320a01a0d2e0ef5f76d3504bbe (diff)
tshark: Run GLib mainloop during capture
Use the timer polling approach on Windows. GLib timer callbacks execute in main thread. Remove useless mutex as there is no point in protecting resources if only can thread can access the resources. Simply wait on capture child handle instead of periodically checking process state. On Unix systems, register the pipe fd for polling inside GLib mainloop.
Diffstat (limited to 'capture')
-rw-r--r--capture/capture_sync.c19
1 files changed, 4 insertions, 15 deletions
diff --git a/capture/capture_sync.c b/capture/capture_sync.c
index 9971099203..9195762364 100644
--- a/capture/capture_sync.c
+++ b/capture/capture_sync.c
@@ -2028,11 +2028,6 @@ signal_pipe_capquit_to_child(capture_session *cap_session)
void
sync_pipe_stop(capture_session *cap_session)
{
-#ifdef _WIN32
- int count;
- DWORD childstatus;
- gboolean terminate = TRUE;
-#endif
if (cap_session->fork_child != WS_INVALID_PID) {
#ifndef _WIN32
/* send the SIGINT signal to close the capture child gracefully. */
@@ -2042,24 +2037,18 @@ sync_pipe_stop(capture_session *cap_session)
}
#else
#define STOP_SLEEP_TIME 500 /* ms */
-#define STOP_CHECK_TIME 50
+ DWORD status;
+
/* First, use the special signal pipe to try to close the capture child
* gracefully.
*/
signal_pipe_capquit_to_child(cap_session);
/* Next, wait for the process to exit on its own */
- for (count = 0; count < STOP_SLEEP_TIME / STOP_CHECK_TIME; count++) {
- if (GetExitCodeProcess((HANDLE) cap_session->fork_child, &childstatus) &&
- childstatus != STILL_ACTIVE) {
- terminate = FALSE;
- break;
- }
- Sleep(STOP_CHECK_TIME);
- }
+ status = WaitForSingleObject((HANDLE) cap_session->fork_child, STOP_SLEEP_TIME);
/* Force the issue. */
- if (terminate) {
+ if (status != WAIT_OBJECT_0) {
ws_warning("sync_pipe_stop: forcing child to exit");
sync_pipe_kill(cap_session->fork_child);
}