diff options
author | tuexen <tuexen@f5534014-38df-0310-8fa8-9805f1628bb7> | 2011-07-16 12:45:47 +0000 |
---|---|---|
committer | tuexen <tuexen@f5534014-38df-0310-8fa8-9805f1628bb7> | 2011-07-16 12:45:47 +0000 |
commit | 518a329ce0388630dc551a52d0524a72f3dd797b (patch) | |
tree | 79529e04545748d2d8d2e38b2aa1aa57058d40fc /dumpcap.c | |
parent | 549800b4d919b541e2937e510663d627aa46c00f (diff) |
Use the threads based workaround only on windows (with thread support enabled),
since the workaround is only intended to work on windows.
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@38059 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'dumpcap.c')
-rw-r--r-- | dumpcap.c | 68 |
1 files changed, 34 insertions, 34 deletions
@@ -237,9 +237,9 @@ typedef struct _pcap_options { #endif gboolean cap_pipe_modified; /* TRUE if data in the pipe uses modified pcap headers */ gboolean cap_pipe_byte_swapped; /* TRUE if data in the pipe is byte swapped */ -#ifdef USE_THREADS +#if defined(USE_THREADS) && defined(_WIN32) char * cap_pipe_buf; /* Pointer to the data buffer we read into */ -#endif /* USE_THREADS */ +#endif int cap_pipe_bytes_to_read;/* Used by cap_pipe_dispatch */ int cap_pipe_bytes_read; /* Used by cap_pipe_dispatch */ enum { @@ -249,7 +249,7 @@ typedef struct _pcap_options { STATE_READ_DATA } cap_pipe_state; enum { PIPOK, PIPEOF, PIPERR, PIPNEXIST } cap_pipe_err; -#ifdef USE_THREADS +#if defined(USE_THREADS) && defined(_WIN32) GMutex *cap_pipe_read_mtx; GAsyncQueue *cap_pipe_pending_q, *cap_pipe_done_q; #endif @@ -320,10 +320,10 @@ static gboolean need_timeout_workaround; * WaitForSingleObject. If it's less than 1000 WaitForSingleObject * will return immediately. */ -#ifndef USE_THREADS -#define PIPE_READ_TIMEOUT 250000 -#else +#if defined(USE_THREADS) && defined(_WIN32) #define PIPE_READ_TIMEOUT 100000 +#else +#define PIPE_READ_TIMEOUT 250000 #endif #define WRITER_THREAD_TIMEOUT 100000 /* usecs */ @@ -1549,7 +1549,7 @@ cap_pipe_adjust_header(gboolean byte_swapped, struct pcap_hdr *hdr, struct pcapr } } -#ifdef USE_THREADS +#if defined(USE_THREADS) && defined(_WIN32) /* * Thread function that reads from a pipe and pushes the data * to the main application thread. @@ -1635,9 +1635,9 @@ static void *cap_pipe_read(void *arg) } return NULL; } -#endif /* USE_THREADS */ +#endif -#if !defined(USE_THREADS) || defined(MUST_DO_SELECT) +#if (!(defined(USE_THREADS) && defined(_WIN32))) || defined(MUST_DO_SELECT) /* Provide select() functionality for a single file descriptor * on UNIX/POSIX. Windows uses cap_pipe_read via a thread. * @@ -1684,7 +1684,7 @@ cap_pipe_open_live(char *pipename, wchar_t *err_str; #endif #endif -#ifndef USE_THREADS +#if !(defined(USE_THREADS) && defined(_WIN32)) int sel_ret; unsigned int bytes_read; #endif @@ -1853,7 +1853,7 @@ cap_pipe_open_live(char *pipename, pcap_opts->from_cap_pipe = TRUE; -#ifndef USE_THREADS +#if !(defined(USE_THREADS) && defined(_WIN32)) /* read the pcap header */ bytes_read = 0; while (bytes_read < sizeof magic) { @@ -1875,7 +1875,7 @@ cap_pipe_open_live(char *pipename, bytes_read += b; } } -#else /* USE_THREADS */ +#else g_thread_create(&cap_pipe_read, pcap_opts, FALSE, NULL); pcap_opts->cap_pipe_buf = (char *) &magic; @@ -1893,7 +1893,7 @@ cap_pipe_open_live(char *pipename, goto error; } -#endif /* USE_THREADS */ +#endif switch (magic) { case PCAP_MAGIC: @@ -1928,7 +1928,7 @@ cap_pipe_open_live(char *pipename, goto error; } -#ifndef USE_THREADS +#if !(defined(USE_THREADS) && defined(_WIN32)) /* Read the rest of the header */ bytes_read = 0; while (bytes_read < sizeof(struct pcap_hdr)) { @@ -1951,7 +1951,7 @@ cap_pipe_open_live(char *pipename, bytes_read += b; } } -#else /* USE_THREADS */ +#else pcap_opts->cap_pipe_buf = (char *) hdr; pcap_opts->cap_pipe_bytes_read = 0; pcap_opts->cap_pipe_bytes_to_read = sizeof(struct pcap_hdr); @@ -1965,7 +1965,7 @@ cap_pipe_open_live(char *pipename, g_strerror(errno)); goto error; } -#endif /* USE_THREADS */ +#endif if (pcap_opts->cap_pipe_byte_swapped) { /* Byte-swap the header fields about which we care. */ @@ -2008,7 +2008,7 @@ cap_pipe_dispatch(loop_data *ld, pcap_options *pcap_opts, guchar *data, char *er struct pcap_pkthdr phdr; enum { PD_REC_HDR_READ, PD_DATA_READ, PD_PIPE_EOF, PD_PIPE_ERR, PD_ERR } result; -#ifdef USE_THREADS +#if defined(USE_THREADS) && defined(_WIN32) GTimeVal wait_time; gpointer q_status; #else @@ -2025,7 +2025,7 @@ cap_pipe_dispatch(loop_data *ld, pcap_options *pcap_opts, guchar *data, char *er switch (pcap_opts->cap_pipe_state) { case STATE_EXPECT_REC_HDR: -#ifdef USE_THREADS +#if defined(USE_THREADS) && defined(_WIN32) if (g_mutex_trylock(pcap_opts->cap_pipe_read_mtx)) { #endif @@ -2034,7 +2034,7 @@ cap_pipe_dispatch(loop_data *ld, pcap_options *pcap_opts, guchar *data, char *er sizeof(struct pcaprec_modified_hdr) : sizeof(struct pcaprec_hdr); pcap_opts->cap_pipe_bytes_read = 0; -#ifdef USE_THREADS +#if defined(USE_THREADS) && defined(_WIN32) pcap_opts->cap_pipe_buf = (char *) &pcap_opts->cap_pipe_rechdr; g_async_queue_push(pcap_opts->cap_pipe_pending_q, pcap_opts->cap_pipe_buf); g_mutex_unlock(pcap_opts->cap_pipe_read_mtx); @@ -2043,7 +2043,7 @@ cap_pipe_dispatch(loop_data *ld, pcap_options *pcap_opts, guchar *data, char *er /* Fall through */ case STATE_READ_REC_HDR: -#ifndef USE_THREADS +#if !(defined(USE_THREADS) && defined(_WIN32)) b = read(pcap_opts->cap_pipe_fd, ((char *)&pcap_opts->cap_pipe_rechdr)+pcap_opts->cap_pipe_bytes_read, pcap_opts->cap_pipe_bytes_to_read - pcap_opts->cap_pipe_bytes_read); if (b <= 0) { @@ -2054,7 +2054,7 @@ cap_pipe_dispatch(loop_data *ld, pcap_options *pcap_opts, guchar *data, char *er break; } pcap_opts->cap_pipe_bytes_read += b; -#else /* USE_THREADS */ +#else g_get_current_time(&wait_time); g_time_val_add(&wait_time, PIPE_READ_TIMEOUT); q_status = g_async_queue_timed_pop(pcap_opts->cap_pipe_done_q, &wait_time); @@ -2068,14 +2068,14 @@ cap_pipe_dispatch(loop_data *ld, pcap_options *pcap_opts, guchar *data, char *er if (!q_status) { return 0; } -#endif /* USE_THREADS */ +#endif if ((pcap_opts->cap_pipe_bytes_read) < pcap_opts->cap_pipe_bytes_to_read) return 0; result = PD_REC_HDR_READ; break; case STATE_EXPECT_DATA: -#ifdef USE_THREADS +#if defined(USE_THREADS) && defined(_WIN32) if (g_mutex_trylock(pcap_opts->cap_pipe_read_mtx)) { #endif @@ -2083,7 +2083,7 @@ cap_pipe_dispatch(loop_data *ld, pcap_options *pcap_opts, guchar *data, char *er pcap_opts->cap_pipe_bytes_to_read = pcap_opts->cap_pipe_rechdr.hdr.incl_len; pcap_opts->cap_pipe_bytes_read = 0; -#ifdef USE_THREADS +#if defined(USE_THREADS) && defined(_WIN32) pcap_opts->cap_pipe_buf = (char *) data; g_async_queue_push(pcap_opts->cap_pipe_pending_q, pcap_opts->cap_pipe_buf); g_mutex_unlock(pcap_opts->cap_pipe_read_mtx); @@ -2092,7 +2092,7 @@ cap_pipe_dispatch(loop_data *ld, pcap_options *pcap_opts, guchar *data, char *er /* Fall through */ case STATE_READ_DATA: -#ifndef USE_THREADS +#if !(defined(USE_THREADS) && defined(_WIN32)) b = read(pcap_opts->cap_pipe_fd, data+pcap_opts->cap_pipe_bytes_read, pcap_opts->cap_pipe_bytes_to_read - pcap_opts->cap_pipe_bytes_read); if (b <= 0) { @@ -2103,7 +2103,7 @@ cap_pipe_dispatch(loop_data *ld, pcap_options *pcap_opts, guchar *data, char *er break; } pcap_opts->cap_pipe_bytes_read += b; -#else /* USE_THREADS */ +#else g_get_current_time(&wait_time); g_time_val_add(&wait_time, PIPE_READ_TIMEOUT); q_status = g_async_queue_timed_pop(pcap_opts->cap_pipe_done_q, &wait_time); @@ -2117,7 +2117,7 @@ cap_pipe_dispatch(loop_data *ld, pcap_options *pcap_opts, guchar *data, char *er if (!q_status) { return 0; } -#endif /* USE_THREADS */ +#endif if ((pcap_opts->cap_pipe_bytes_read) < pcap_opts->cap_pipe_bytes_to_read) return 0; result = PD_DATA_READ; @@ -2294,14 +2294,14 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld, #endif pcap_opts->cap_pipe_modified = FALSE; pcap_opts->cap_pipe_byte_swapped = FALSE; -#ifdef USE_THREADS +#if defined(USE_THREADS) && defined(_WIN32) pcap_opts->cap_pipe_buf = NULL; -#endif /* USE_THREADS */ +#endif pcap_opts->cap_pipe_bytes_to_read = 0; pcap_opts->cap_pipe_bytes_read = 0; pcap_opts->cap_pipe_state = 0; pcap_opts->cap_pipe_err = PIPOK; -#ifdef USE_THREADS +#if defined(USE_THREADS) && defined(_WIN32) pcap_opts->cap_pipe_read_mtx = g_mutex_new(); pcap_opts->cap_pipe_pending_q = g_async_queue_new(); pcap_opts->cap_pipe_done_q = g_async_queue_new(); @@ -2638,7 +2638,7 @@ capture_loop_dispatch(loop_data *ld, int inpkts; gint packet_count_before; guchar pcap_data[WTAP_MAX_PACKET_SIZE]; -#ifndef USE_THREADS +#if !(defined(USE_THREADS) && defined(_WIN32)) int sel_ret; #endif @@ -2648,7 +2648,7 @@ capture_loop_dispatch(loop_data *ld, #ifdef LOG_CAPTURE_VERBOSE g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_dispatch: from capture pipe"); #endif -#ifndef USE_THREADS +#if !(defined(USE_THREADS) && defined(_WIN32)) sel_ret = cap_pipe_select(pcap_opts->cap_pipe_fd); if (sel_ret <= 0) { if (sel_ret < 0 && errno != EINTR) { @@ -2661,12 +2661,12 @@ capture_loop_dispatch(loop_data *ld, /* * "select()" says we can read from the pipe without blocking */ -#endif /* USE_THREADS */ +#endif inpkts = cap_pipe_dispatch(ld, pcap_opts, pcap_data, errmsg, errmsg_len); if (inpkts < 0) { ld->go = FALSE; } -#ifndef USE_THREADS +#if !(defined(USE_THREADS) && defined(_WIN32)) } #endif } |