]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/eventreader.h
EventReader class
[libs/core.git] / source / io / eventreader.h
diff --git a/source/io/eventreader.h b/source/io/eventreader.h
new file mode 100644 (file)
index 0000000..b3acdb9
--- /dev/null
@@ -0,0 +1,43 @@
+#ifndef MSP_IO_EVENTREADER_H_
+#define MSP_IO_EVENTREADER_H_
+
+#include "handle.h"
+
+namespace Msp {
+namespace IO {
+
+/**
+Helper class for reading data in a way that supports events.  For internal use
+only.
+
+On Windows, overlapped reads are used.  Data is read to an internal buffer and
+handed out from there.  An event object is kept synchronized with the buffer
+state to get level-triggered semantics for poll.  Whenever the buffer becomes
+empty, a new overlapped read is started.
+
+Unix-based systems can poll the fd directly, so this class reduces to a simple
+passthrough to sys_read.
+*/
+class EventReader
+{
+private:
+       struct Private;
+
+       Handle &handle;
+       Private *priv;
+
+public:
+       EventReader(Handle &, unsigned);
+       ~EventReader();
+
+       const Handle &get_event() const;
+
+       void start();
+       void wait();
+       unsigned read(char *, unsigned);
+};
+
+} // namespace IO
+} // namespace Msp
+
+#endif