aboutsummaryrefslogtreecommitdiffstats
path: root/dumpcap.c
diff options
context:
space:
mode:
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2010-09-30 01:01:25 +0000
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2010-09-30 01:01:25 +0000
commitc863f64b9a9d6e49b5d9980a0ec854b0ef93cadc (patch)
treeb3638a6ac9eb345611fd3709a28b37f311d61e19 /dumpcap.c
parent243f7331c5ba7927187a88a67a0736adfb137be3 (diff)
Always use a timeout of 250ms for pipes when not using threads; that way
we know it's < 1s, and don't have to worry about properly setting tv_sec and tv_usec for select(). Get rid of unneeded pointer variable. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@34282 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'dumpcap.c')
-rw-r--r--dumpcap.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/dumpcap.c b/dumpcap.c
index 4cb1b6c944..8f50d8b42e 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -278,11 +278,12 @@ static loop_data global_ld;
/*
- * Timeout, in milliseconds, for reads from the stream of captured packets.
+ * Timeout, in milliseconds, for reads from the stream of captured packets
+ * from a capture device.
*
* A bug in Mac OS X 10.6 and 10.6.1 causes calls to pcap_open_live(), in
* 64-bit applications, with sub-second timeouts not to work. The bug is
- * fixed in 10.6.2.
+ * fixed in 10.6.2 and re-broken in 10.6.3.
*/
#if defined(__APPLE__) && defined(__LP64__)
static gboolean need_timeout_workaround;
@@ -293,9 +294,18 @@ static gboolean need_timeout_workaround;
#endif
/*
- * Timeout, in microseconds, for threaded reads from a pipe.
+ * Timeout, in microseconds, for reads from the stream of captured packets
+ * from a pipe. Pipes doesn't have the same problem that BPF devices do
+ * in OS X 10.6, 10.6.1, 10.6.3, and 10.6.4, so we always use a timeout
+ * of 250ms.
+ *
+ * XXX - why was it 100 for threaded capturing?
*/
-#define THREAD_READ_TIMEOUT 100
+#ifndef USE_THREADS
+#define PIPE_READ_TIMEOUT 250
+#else
+#define PIPE_READ_TIMEOUT 100
+#endif
static const char *cap_pipe_err_str;
static void
@@ -1569,7 +1579,7 @@ static void *cap_pipe_read(void *ld_ptr) {
static int
cap_pipe_select(int pipe_fd) {
fd_set rfds;
- struct timeval timeout, *pto;
+ struct timeval timeout;
int sel_ret;
cap_pipe_err_str = "Unknown error";
@@ -1578,10 +1588,9 @@ cap_pipe_select(int pipe_fd) {
FD_SET(pipe_fd, &rfds);
timeout.tv_sec = 0;
- timeout.tv_usec = CAP_READ_TIMEOUT * 1000;
- pto = &timeout;
+ timeout.tv_usec = PIPE_READ_TIMEOUT * 1000;
- sel_ret = select(pipe_fd+1, &rfds, NULL, NULL, pto);
+ sel_ret = select(pipe_fd+1, &rfds, NULL, NULL, &timeout);
if (sel_ret < 0)
cap_pipe_err_str = strerror(errno);
return sel_ret;
@@ -1980,7 +1989,7 @@ cap_pipe_dispatch(loop_data *ld, guchar *data, char *errmsg, int errmsgl)
ld->cap_pipe_bytes_read += b;
#else /* USE_THREADS */
g_get_current_time(&wait_time);
- g_time_val_add(&wait_time, THREAD_READ_TIMEOUT);
+ g_time_val_add(&wait_time, PIPE_READ_TIMEOUT);
q_status = g_async_queue_timed_pop(cap_pipe_done_q, &wait_time);
if (ld->cap_pipe_err == PIPEOF) {
result = PD_PIPE_EOF;
@@ -2029,7 +2038,7 @@ cap_pipe_dispatch(loop_data *ld, guchar *data, char *errmsg, int errmsgl)
ld->cap_pipe_bytes_read += b;
#else /* USE_THREADS */
g_get_current_time(&wait_time);
- g_time_val_add(&wait_time, THREAD_READ_TIMEOUT);
+ g_time_val_add(&wait_time, PIPE_READ_TIMEOUT);
q_status = g_async_queue_timed_pop(cap_pipe_done_q, &wait_time);
if (ld->cap_pipe_err == PIPEOF) {
result = PD_PIPE_EOF;