From 537f5831c4400dea7fa15032c4cd6bd2fae86bb1 Mon Sep 17 00:00:00 2001 From: imarom Date: Mon, 28 Nov 2016 11:25:32 +0200 Subject: RX features - self code review Signed-off-by: imarom --- src/common/captureFile.h | 5 +++-- src/common/erf.cpp | 6 +++++- src/common/erf.h | 7 +++++++ src/common/pcap.cpp | 6 ++++++ src/common/pcap.h | 7 +++++++ 5 files changed, 28 insertions(+), 3 deletions(-) (limited to 'src/common') diff --git a/src/common/captureFile.h b/src/common/captureFile.h index fefa62bd..d87e57b6 100755 --- a/src/common/captureFile.h +++ b/src/common/captureFile.h @@ -227,9 +227,10 @@ class CFileWriterBase { public: - virtual ~CFileWriterBase(){}; - virtual bool Create(char * name) = 0; + virtual ~CFileWriterBase(){}; + virtual bool Create(char * name) = 0; virtual bool write_packet(CCapPktRaw * lpPacket)=0; + virtual void flush_to_disk() = 0; }; diff --git a/src/common/erf.cpp b/src/common/erf.cpp index 76945b01..f872a281 100755 --- a/src/common/erf.cpp +++ b/src/common/erf.cpp @@ -280,7 +280,11 @@ bool CErfFileWriter::write_packet(CCapPktRaw * lpPacket){ return true; } - +void CErfFileWriter::flush_to_disk() { + if (m_fd) { + fflush(m_fd); + } +} bool CPcapFileWriter::Create(char *file_name){ m_fd=CAP_FOPEN_64(file_name,"wb"); diff --git a/src/common/erf.h b/src/common/erf.h index e1b83e46..bec94872 100755 --- a/src/common/erf.h +++ b/src/common/erf.h @@ -224,6 +224,13 @@ public: virtual bool Create(char *file_name); void Delete(); virtual bool write_packet(CCapPktRaw * lpPacket); + + /** + * flush all packets to disk + * + */ + void flush_to_disk(); + private: FILE *m_fd; int m_cnt; diff --git a/src/common/pcap.cpp b/src/common/pcap.cpp index 8e9bf0ac..f5eb3c41 100755 --- a/src/common/pcap.cpp +++ b/src/common/pcap.cpp @@ -228,6 +228,12 @@ bool LibPCapWriter::Create(char * name) return init(); } +void LibPCapWriter::flush_to_disk() { + if (m_is_open) { + fflush(m_file_handler); + } +} + /** * * Write the libpcap header. diff --git a/src/common/pcap.h b/src/common/pcap.h index c9139e4c..265ea17b 100755 --- a/src/common/pcap.h +++ b/src/common/pcap.h @@ -143,6 +143,13 @@ public: */ void Close(); + /** + * flush all packets to disk + * + * @author imarom (11/24/2016) + */ + void flush_to_disk(); + private: bool init(); -- cgit 1.2.3-korg