aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2018-12-01 18:32:28 -0800
committerAnders Broman <a.broman58@gmail.com>2018-12-02 07:51:54 +0000
commit4154e35cde9c863ace57598cabc37034dab2ab1c (patch)
treec287c3fd89e069f51479dbb481874e3e34b81249
parent82ebab607ec4634021f3b6a2ffadb06efcd6900c (diff)
maxmind: Simplify our read logic.
Don't bother checking to see if our pipe has data. Change-Id: I55f24850a16f66be9c679ad51e35df9f35c206db Reviewed-on: https://code.wireshark.org/review/30877 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--epan/maxmind_db.c42
1 files changed, 14 insertions, 28 deletions
diff --git a/epan/maxmind_db.c b/epan/maxmind_db.c
index 9170cb23a1..661ed4f663 100644
--- a/epan/maxmind_db.c
+++ b/epan/maxmind_db.c
@@ -180,23 +180,10 @@ write_mmdbr_stdin_worker(gpointer sifd_data) {
return NULL;
}
-static ssize_t mmdbr_pipe_read_one(char *ch_p) {
- ssize_t status = -1;
- g_rw_lock_reader_lock(&mmdbr_pipe_mtx);
- if (ws_pipe_valid(&mmdbr_pipe) && ws_pipe_data_available(mmdbr_pipe.stdout_fd)) {
- status = ws_read(mmdbr_pipe.stdout_fd, ch_p, 1);
- }
- g_rw_lock_reader_unlock(&mmdbr_pipe_mtx);
- return status;
-}
-
// We need to read a series of lines from mmdbresolve's stdout. Trying to
-// use fgets is problematic because it blocks on Windows blocks. Doing so
-// in a thread is even worse since it locks the I/O stream and if the main
+// use fgets is problematic because it blocks on Windows. Doing so in a
+// thread is even worse since it locks the I/O stream and if the main
// thread calls fclose while fgets is blocking, it will block as well.
-//
-// Read our input one character at a time and only after we've ensured
-// that data is available.
#define MAX_MMDB_LINE_LEN 2000
static gpointer
read_mmdbr_stdout_worker(gpointer data _U_) {
@@ -212,11 +199,17 @@ read_mmdbr_stdout_worker(gpointer data _U_) {
while (1) { // Start of line
char cur_addr[WS_INET6_ADDRSTRLEN];
char ch;
- ssize_t status;
+ ssize_t resp_status;
g_string_truncate(line_buf, 0);
- while((status = mmdbr_pipe_read_one(&ch)) == 1) {
+ if (!mmdbr_pipe_valid()) {
+ // Should be due to mmdb_resolve_stop.
+ MMDB_DEBUG("invalid mmdbr stdout pipe. exiting thread.");
+ break;
+ }
+
+ while((resp_status = ws_read(mmdbr_pipe.stdout_fd, &ch, 1)) == 1) {
if (ch == '\n') {
break;
}
@@ -224,21 +217,14 @@ read_mmdbr_stdout_worker(gpointer data _U_) {
g_string_append_c(line_buf, ch);
if (line_buf->len > MAX_MMDB_LINE_LEN) {
- MMDB_DEBUG("long line");
+ MMDB_DEBUG("long line. marking invalid.");
g_string_printf(line_buf, "%s", RES_INVALID_LINE);
}
}
- if (status != 1) {
- if (!mmdbr_pipe_valid()) {
- // Should be due to mmdb_resolve_stop.
- MMDB_DEBUG("invalid mmdbr stdout pipe. exiting thread.");
- break;
- }
-
- MMDB_DEBUG("no pipe data");
- g_usleep(MMDB_WAIT_TIME);
- continue;
+ if (resp_status != 1) {
+ MMDB_DEBUG("read error %s. exiting thread.", g_strerror(errno));
+ break;
}
char *line = g_strstrip(line_buf->str);