aboutsummaryrefslogtreecommitdiffstats
path: root/ringbuffer.c
diff options
context:
space:
mode:
authorAnders Broman <anders.broman@ericsson.com>2019-01-03 15:51:56 +0100
committerAnders Broman <a.broman58@gmail.com>2019-03-10 12:34:55 +0000
commita55111610a296f69b9e066c59a9f3bc16f1f542a (patch)
tree982b9260e8663e861c85bb81e30bfe1ee9b823d5 /ringbuffer.c
parent101fed9420eeeefd8a2033d67a466c7c4c2231f8 (diff)
Dumpcap: Set a bigger IO buffer (64KiB).
Set a bigger IO buffer to avoid syscall overhead. See https://github.com/the-tcpdump-group/libpcap/issues/792 Change-Id: If370da5ab2b70a9d0c925dd7c4c5c135c675c3f6 Reviewed-on: https://code.wireshark.org/review/31326 Petri-Dish: Anders Broman <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ringbuffer.c')
-rw-r--r--ringbuffer.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/ringbuffer.c b/ringbuffer.c
index b84c032086..1251ed3057 100644
--- a/ringbuffer.c
+++ b/ringbuffer.c
@@ -50,18 +50,19 @@ typedef struct _rb_file {
gchar *name;
} rb_file;
-/* Ringbuffer data structure */
+/** Ringbuffer data structure */
typedef struct _ringbuf_data {
rb_file *files;
- guint num_files; /* Number of ringbuffer files (1 to ...) */
- guint curr_file_num; /* Number of the current file (ever increasing) */
- gchar *fprefix; /* Filename prefix */
- gchar *fsuffix; /* Filename suffix */
- gboolean unlimited; /* TRUE if unlimited number of files */
+ guint num_files; /**< Number of ringbuffer files (1 to ...) */
+ guint curr_file_num; /**< Number of the current file (ever increasing) */
+ gchar *fprefix; /**< Filename prefix */
+ gchar *fsuffix; /**< Filename suffix */
+ gboolean unlimited; /**< TRUE if unlimited number of files */
- int fd; /* Current ringbuffer file descriptor */
+ int fd; /**< Current ringbuffer file descriptor */
FILE *pdh;
- gboolean group_read_access; /* TRUE if files need to be opened with group read access */
+ char *io_buffer; /**< The IO buffer used to write to the file */
+ gboolean group_read_access; /**< TRUE if files need to be opened with group read access */
} ringbuf_data;
static ringbuf_data rb_data;
@@ -229,7 +230,22 @@ ringbuf_init_libpcap_fdopen(int *err)
if (err != NULL) {
*err = errno;
}
+ } else {
+ size_t buffsize = IO_BUF_SIZE;
+#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
+ ws_statb64 statb;
+
+ if (ws_fstat64(rb_data.fd, &statb) == 0) {
+ if (statb.st_blksize > IO_BUF_SIZE) {
+ buffsize = statb.st_blksize;
+ }
+ }
+#endif
+ /* Increase the size of the IO bubffer */
+ rb_data.io_buffer = (char *)g_malloc(buffsize);
+ setvbuf(rb_data.pdh, rb_data.io_buffer, _IOFBF, buffsize);
}
+
return rb_data.pdh;
}
@@ -251,6 +267,8 @@ ringbuf_switch_file(FILE **pdh, gchar **save_file, int *save_file_fd, int *err)
ws_close(rb_data.fd); /* XXX - the above should have closed this already */
rb_data.pdh = NULL; /* it's still closed, we just got an error while closing */
rb_data.fd = -1;
+ g_free(rb_data.io_buffer);
+ rb_data.io_buffer = NULL;
return FALSE;
}
@@ -298,6 +316,9 @@ ringbuf_libpcap_dump_close(gchar **save_file, int *err)
}
rb_data.pdh = NULL;
rb_data.fd = -1;
+ g_free(rb_data.io_buffer);
+ rb_data.io_buffer = NULL;
+
}
/* set the save file name to the current file */
@@ -362,6 +383,9 @@ ringbuf_error_cleanup(void)
}
}
}
+ g_free(rb_data.io_buffer);
+ rb_data.io_buffer = NULL;
+
/* free the memory */
ringbuf_free();
}