Zlib has an officially-sanctioned way of clearing EOF when we're tailing

a file.  Use it.

svn path=/trunk/; revision=32716
This commit is contained in:
Gerald Combs 2010-05-07 21:15:24 +00:00
parent 52cbbd605f
commit 0a209d762e
3 changed files with 18 additions and 9 deletions

1
file.c
View File

@ -801,6 +801,7 @@ cf_continue_tail(capture_file *cf, volatile int to_read, int *err)
/*g_log(NULL, G_LOG_LEVEL_MESSAGE, "cf_continue_tail: %u new: %u", cf->count, to_read);*/
wtap_cleareof(cf->wth);
while (to_read != 0 && (wtap_read(cf->wth, err, &err_info, &data_offset))) {
if (cf->state == FILE_READ_ABORTED) {
/* Well, the user decided to exit Wireshark. Break out of the

View File

@ -637,6 +637,15 @@ wtap_close(wtap *wth)
g_free(wth);
}
void
wtap_cleareof(wtap *wth) {
#ifdef HAVE_LIBZ
/* Reset EOF */
if (gzeof(wth->fh))
gzclearerr(wth->fh);
#endif
}
gboolean
wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
@ -650,14 +659,6 @@ wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
*/
wth->phdr.pkt_encap = wth->file_encap;
#if defined(ZLIB_VERNUM) && ZLIB_VERNUM == 0x1250
/* Reset EOF */
/* g_log(NULL, G_LOG_LEVEL_DEBUG, "wtap_read: eof before seek: %d", gzeof(wth->fh)); */
if (gzeof(wth->fh))
gzseek(wth->fh, 0, SEEK_CUR);
/* g_log(NULL, G_LOG_LEVEL_DEBUG, "wtap_read: eof after seek: %d", gzeof(wth->fh)); */
#endif
if (!wth->subtype_read(wth, err, err_info, data_offset))
return FALSE; /* failure */

View File

@ -886,7 +886,7 @@ struct gsm_um_phdr {
#define GSM_UM_CHANNEL_RACH 6
#define GSM_UM_CHANNEL_AGCH 7
#define GSM_UM_CHANNEL_PCH 8
union wtap_pseudo_header {
struct eth_phdr eth;
struct x25_phdr x25;
@ -972,6 +972,13 @@ typedef int (*wtap_open_routine_t)(struct wtap*, int *, char **);
struct wtap* wtap_open_offline(const char *filename, int *err,
gchar **err_info, gboolean do_random);
/*
* If we were compiled with zlib and we're at EOF, unset EOF so that
* wtap_read/gzread has a chance to succeed. This is necessary if
* we're tailing a file.
*/
void wtap_cleareof(wtap *wth);
/* Returns TRUE if read was successful. FALSE if failure. data_offset is
* set to the offset in the file where the data for the read packet is
* located. */