summaryrefslogtreecommitdiff
path: root/lib/common/IOStream.cpp
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2008-08-21 11:05:38 +0000
committerChris Wilson <chris+github@qwirx.com>2008-08-21 11:05:38 +0000
commit67279841cd455a04470515dd9e4db0cd7af46651 (patch)
tree42cf7f37a2ab5d13208a7ef362d60fa506f17f50 /lib/common/IOStream.cpp
parent96c337af8c1b79911fe0268db9337970f794094c (diff)
Add a Flush() method to IOStream to read and discard all remaining data,
and a SelfFlushingStream class which can be used to ensure that protocol streams are always flushed, to avoid breaking protocol.
Diffstat (limited to 'lib/common/IOStream.cpp')
-rw-r--r--lib/common/IOStream.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/common/IOStream.cpp b/lib/common/IOStream.cpp
index 3c7be561..76fb7fed 100644
--- a/lib/common/IOStream.cpp
+++ b/lib/common/IOStream.cpp
@@ -238,4 +238,24 @@ bool IOStream::CopyStreamTo(IOStream &rCopyTo, int Timeout, int BufferSize)
return true; // completed
}
+// --------------------------------------------------------------------------
+//
+// Function
+// Name: IOStream::Flush(int Timeout)
+// Purpose: Read and discard all remaining data in stream.
+// Useful for protocol streams which must be flushed
+// to avoid breaking the protocol.
+// Created: 2008/08/20
+//
+// --------------------------------------------------------------------------
+void IOStream::Flush(int Timeout)
+{
+ char buffer[4096];
+
+ while(StreamDataLeft())
+ {
+ Read(buffer, sizeof(buffer), Timeout);
+ }
+}
+