forked from osmocom/wireshark
Revert r44644 and 44645. g_source_*, g_timeout_, and g_io_* all depend
on the GLib main loop which isn't portable (unless you want to want to manage the main loop yourself). git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@44655 f5534014-38df-0310-8fa8-9805f1628bb7
This commit is contained in:
parent
a40f550ee5
commit
13098a37b6
|
@ -722,7 +722,6 @@ if( (BUILD_wireshark AND GTK_FOUND) OR (BUILD_qtshark AND QT_FOUND) )
|
|||
u3.c
|
||||
ui/alert_box.c
|
||||
ui/iface_lists.c
|
||||
ui/pipe_input.c
|
||||
ui/util.c
|
||||
ws80211_utils.c
|
||||
${SHARK_COMMON_CAPTURE_SRC}
|
||||
|
|
|
@ -98,7 +98,6 @@
|
|||
#include "capture-wpcap.h"
|
||||
#endif
|
||||
|
||||
#include "ui/pipe_input.h"
|
||||
#include "ui/ui_util.h"
|
||||
|
||||
#include <wsutil/file_util.h>
|
||||
|
|
|
@ -43,7 +43,6 @@ GENERATOR_FILES =
|
|||
WIRESHARK_UI_SRC = \
|
||||
alert_box.c \
|
||||
iface_lists.c \
|
||||
pipe_input.c \
|
||||
util.c
|
||||
|
||||
noinst_HEADERS = \
|
||||
|
@ -52,7 +51,6 @@ noinst_HEADERS = \
|
|||
last_open_dir.h \
|
||||
iface_lists.h \
|
||||
main_statusbar.h \
|
||||
pipe_input.h \
|
||||
progress_dlg.h \
|
||||
recent.h \
|
||||
recent_utils.h \
|
||||
|
|
|
@ -642,6 +642,151 @@ void main_window_quit(void)
|
|||
gtk_main_quit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
typedef struct pipe_input_tag {
|
||||
gint source;
|
||||
gpointer user_data;
|
||||
int *child_process;
|
||||
pipe_input_cb_t input_cb;
|
||||
guint pipe_input_id;
|
||||
#ifdef _WIN32
|
||||
#else
|
||||
GIOChannel *channel;
|
||||
#endif
|
||||
} pipe_input_t;
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
/* The timer has expired, see if there's stuff to read from the pipe,
|
||||
if so, do the callback */
|
||||
static gboolean
|
||||
pipe_timer_cb(gpointer data)
|
||||
{
|
||||
HANDLE handle;
|
||||
DWORD avail = 0;
|
||||
gboolean result, result1;
|
||||
DWORD childstatus;
|
||||
pipe_input_t *pipe_input = data;
|
||||
gint iterations = 0;
|
||||
|
||||
|
||||
/* try to read data from the pipe only 5 times, to avoid blocking */
|
||||
while(iterations < 5) {
|
||||
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: new iteration");*/
|
||||
|
||||
/* Oddly enough although Named pipes don't work on win9x,
|
||||
PeekNamedPipe does !!! */
|
||||
handle = (HANDLE) _get_osfhandle (pipe_input->source);
|
||||
result = PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL);
|
||||
|
||||
/* Get the child process exit status */
|
||||
result1 = GetExitCodeProcess((HANDLE)*(pipe_input->child_process),
|
||||
&childstatus);
|
||||
|
||||
/* If the Peek returned an error, or there are bytes to be read
|
||||
or the childwatcher thread has terminated then call the normal
|
||||
callback */
|
||||
if (!result || avail > 0 || childstatus != STILL_ACTIVE) {
|
||||
|
||||
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: data avail");*/
|
||||
|
||||
if(pipe_input->pipe_input_id != 0) {
|
||||
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: stop timer");*/
|
||||
/* avoid reentrancy problems and stack overflow */
|
||||
g_source_remove(pipe_input->pipe_input_id);
|
||||
pipe_input->pipe_input_id = 0;
|
||||
}
|
||||
|
||||
/* And call the real handler */
|
||||
if (!pipe_input->input_cb(pipe_input->source, pipe_input->user_data)) {
|
||||
g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: input pipe closed, iterations: %u", iterations);
|
||||
/* pipe closed, return false so that the old timer is not run again */
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: no data avail");*/
|
||||
/* No data, stop now */
|
||||
break;
|
||||
}
|
||||
|
||||
iterations++;
|
||||
}
|
||||
|
||||
if(pipe_input->pipe_input_id == 0) {
|
||||
/* restore pipe handler */
|
||||
pipe_input->pipe_input_id = g_timeout_add(200, pipe_timer_cb, data);
|
||||
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: finished with iterations: %u, new timer", iterations);*/
|
||||
|
||||
/* Return false so that the old timer is not run again */
|
||||
return FALSE;
|
||||
} else {
|
||||
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: finished with iterations: %u, old timer", iterations);*/
|
||||
|
||||
/* we didn't stopped the old timer, so let it run */
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
#else /* _WIN32 */
|
||||
|
||||
/* There's stuff to read from the sync pipe, meaning the child has sent
|
||||
us a message, or the sync pipe has closed, meaning the child has
|
||||
closed it (perhaps because it exited). */
|
||||
static gboolean
|
||||
pipe_input_cb(GIOChannel *source _U_, GIOCondition condition _U_,
|
||||
gpointer data)
|
||||
{
|
||||
pipe_input_t *pipe_input = data;
|
||||
|
||||
|
||||
/* avoid reentrancy problems and stack overflow */
|
||||
g_source_remove(pipe_input->pipe_input_id);
|
||||
|
||||
if (pipe_input->input_cb(pipe_input->source, pipe_input->user_data)) {
|
||||
/* restore pipe handler */
|
||||
pipe_input->pipe_input_id = g_io_add_watch_full (pipe_input->channel,
|
||||
G_PRIORITY_HIGH,
|
||||
G_IO_IN|G_IO_ERR|G_IO_HUP,
|
||||
pipe_input_cb,
|
||||
pipe_input,
|
||||
NULL);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
void pipe_input_set_handler(gint source, gpointer user_data, int *child_process, pipe_input_cb_t input_cb)
|
||||
{
|
||||
static pipe_input_t pipe_input;
|
||||
|
||||
pipe_input.source = source;
|
||||
pipe_input.child_process = child_process;
|
||||
pipe_input.user_data = user_data;
|
||||
pipe_input.input_cb = input_cb;
|
||||
|
||||
#ifdef _WIN32
|
||||
/* Tricky to use pipes in win9x, as no concept of wait. NT can
|
||||
do this but that doesn't cover all win32 platforms. GTK can do
|
||||
this but doesn't seem to work over processes. Attempt to do
|
||||
something similar here, start a timer and check for data on every
|
||||
timeout. */
|
||||
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_input_set_handler: new");*/
|
||||
pipe_input.pipe_input_id = g_timeout_add(200, pipe_timer_cb, &pipe_input);
|
||||
#else
|
||||
pipe_input.channel = g_io_channel_unix_new(source);
|
||||
g_io_channel_set_encoding(pipe_input.channel, NULL, NULL);
|
||||
pipe_input.pipe_input_id = g_io_add_watch_full(pipe_input.channel,
|
||||
G_PRIORITY_HIGH,
|
||||
G_IO_IN|G_IO_ERR|G_IO_HUP,
|
||||
pipe_input_cb,
|
||||
&pipe_input,
|
||||
NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#endif /* HAVE_LIBPCAP */
|
||||
|
||||
/* Given a pointer to a GtkWidget for a top-level window, raise it and
|
||||
|
|
182
ui/pipe_input.c
182
ui/pipe_input.c
|
@ -1,182 +0,0 @@
|
|||
/* pipe_input.c
|
||||
* Pipe input routines. Declared in pipe_input.h
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "pipe_input.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBPCAP
|
||||
|
||||
typedef struct pipe_input_tag {
|
||||
gint source;
|
||||
gpointer user_data;
|
||||
int *child_process;
|
||||
pipe_input_cb_t input_cb;
|
||||
guint pipe_input_id;
|
||||
#ifdef _WIN32
|
||||
#else
|
||||
GIOChannel *channel;
|
||||
#endif
|
||||
} pipe_input_t;
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
/* The timer has expired, see if there's stuff to read from the pipe,
|
||||
if so, do the callback */
|
||||
static gboolean
|
||||
pipe_timer_cb(gpointer data)
|
||||
{
|
||||
HANDLE handle;
|
||||
DWORD avail = 0;
|
||||
gboolean result, result1;
|
||||
DWORD childstatus;
|
||||
pipe_input_t *pipe_input = data;
|
||||
gint iterations = 0;
|
||||
|
||||
|
||||
/* try to read data from the pipe only 5 times, to avoid blocking */
|
||||
while(iterations < 5) {
|
||||
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: new iteration");*/
|
||||
|
||||
/* Oddly enough although Named pipes don't work on win9x,
|
||||
PeekNamedPipe does !!! */
|
||||
handle = (HANDLE) _get_osfhandle (pipe_input->source);
|
||||
result = PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL);
|
||||
|
||||
/* Get the child process exit status */
|
||||
result1 = GetExitCodeProcess((HANDLE)*(pipe_input->child_process),
|
||||
&childstatus);
|
||||
|
||||
/* If the Peek returned an error, or there are bytes to be read
|
||||
or the childwatcher thread has terminated then call the normal
|
||||
callback */
|
||||
if (!result || avail > 0 || childstatus != STILL_ACTIVE) {
|
||||
|
||||
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: data avail");*/
|
||||
|
||||
if(pipe_input->pipe_input_id != 0) {
|
||||
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: stop timer");*/
|
||||
/* avoid reentrancy problems and stack overflow */
|
||||
g_source_remove(pipe_input->pipe_input_id);
|
||||
pipe_input->pipe_input_id = 0;
|
||||
}
|
||||
|
||||
/* And call the real handler */
|
||||
if (!pipe_input->input_cb(pipe_input->source, pipe_input->user_data)) {
|
||||
g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: input pipe closed, iterations: %u", iterations);
|
||||
/* pipe closed, return false so that the old timer is not run again */
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: no data avail");*/
|
||||
/* No data, stop now */
|
||||
break;
|
||||
}
|
||||
|
||||
iterations++;
|
||||
}
|
||||
|
||||
if(pipe_input->pipe_input_id == 0) {
|
||||
/* restore pipe handler */
|
||||
pipe_input->pipe_input_id = g_timeout_add(200, pipe_timer_cb, data);
|
||||
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: finished with iterations: %u, new timer", iterations);*/
|
||||
|
||||
/* Return false so that the old timer is not run again */
|
||||
return FALSE;
|
||||
} else {
|
||||
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: finished with iterations: %u, old timer", iterations);*/
|
||||
|
||||
/* we didn't stopped the old timer, so let it run */
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
#else /* _WIN32 */
|
||||
|
||||
/* There's stuff to read from the sync pipe, meaning the child has sent
|
||||
us a message, or the sync pipe has closed, meaning the child has
|
||||
closed it (perhaps because it exited). */
|
||||
static gboolean
|
||||
pipe_input_cb(GIOChannel *source _U_, GIOCondition condition _U_,
|
||||
gpointer data)
|
||||
{
|
||||
pipe_input_t *pipe_input = data;
|
||||
|
||||
|
||||
/* avoid reentrancy problems and stack overflow */
|
||||
g_source_remove(pipe_input->pipe_input_id);
|
||||
|
||||
if (pipe_input->input_cb(pipe_input->source, pipe_input->user_data)) {
|
||||
/* restore pipe handler */
|
||||
pipe_input->pipe_input_id = g_io_add_watch_full (pipe_input->channel,
|
||||
G_PRIORITY_HIGH,
|
||||
G_IO_IN|G_IO_ERR|G_IO_HUP,
|
||||
pipe_input_cb,
|
||||
pipe_input,
|
||||
NULL);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
void pipe_input_set_handler(gint source, gpointer user_data, int *child_process, pipe_input_cb_t input_cb)
|
||||
{
|
||||
static pipe_input_t pipe_input;
|
||||
|
||||
pipe_input.source = source;
|
||||
pipe_input.child_process = child_process;
|
||||
pipe_input.user_data = user_data;
|
||||
pipe_input.input_cb = input_cb;
|
||||
|
||||
#ifdef _WIN32
|
||||
/* Tricky to use pipes in win9x, as no concept of wait. NT can
|
||||
do this but that doesn't cover all win32 platforms. GTK can do
|
||||
this but doesn't seem to work over processes. Attempt to do
|
||||
something similar here, start a timer and check for data on every
|
||||
timeout. */
|
||||
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_input_set_handler: new");*/
|
||||
pipe_input.pipe_input_id = g_timeout_add(200, pipe_timer_cb, &pipe_input);
|
||||
#else /* _WIN32 */
|
||||
pipe_input.channel = g_io_channel_unix_new(source);
|
||||
g_io_channel_set_encoding(pipe_input.channel, NULL, NULL);
|
||||
pipe_input.pipe_input_id = g_io_add_watch_full(pipe_input.channel,
|
||||
G_PRIORITY_HIGH,
|
||||
G_IO_IN|G_IO_ERR|G_IO_HUP,
|
||||
pipe_input_cb,
|
||||
&pipe_input,
|
||||
NULL);
|
||||
#endif /* _WIN32 */
|
||||
}
|
||||
|
||||
#endif /* HAVE_LIBPCAP */
|
|
@ -1,45 +0,0 @@
|
|||
/* pipe_input.h
|
||||
* Declarations of pipe input routines.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __PIPE_INPUT_H__
|
||||
#define __PIPE_INPUT_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef HAVE_LIBPCAP
|
||||
|
||||
/* Read from a pipe (callback) */
|
||||
typedef gboolean (*pipe_input_cb_t) (gint source, gpointer user_data);
|
||||
/* Install callback function, called if pipe input is available */
|
||||
extern void pipe_input_set_handler(gint source, gpointer user_data, int *child_process, pipe_input_cb_t input_cb);
|
||||
|
||||
#endif /* HAVE_LIBPCAP */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __PIPE_INPUT_H__ */
|
|
@ -56,6 +56,11 @@ extern void main_window_nested_quit(void);
|
|||
/* quit the main window */
|
||||
extern void main_window_quit(void);
|
||||
|
||||
/* read from a pipe (callback) */
|
||||
typedef gboolean (*pipe_input_cb_t) (gint source, gpointer user_data);
|
||||
/* install callback function, called if pipe input is available */
|
||||
extern void pipe_input_set_handler(gint source, gpointer user_data, int *child_process, pipe_input_cb_t input_cb);
|
||||
|
||||
/* packet_list.c */
|
||||
|
||||
void new_packet_list_clear(void);
|
||||
|
|
Loading…
Reference in New Issue