]> git.tdb.fi Git - libs/core.git/blob - source/io/eventreader.h
Add a NonCopyable utility base class
[libs/core.git] / source / io / eventreader.h
1 #ifndef MSP_IO_EVENTREADER_H_
2 #define MSP_IO_EVENTREADER_H_
3
4 #include "handle.h"
5
6 namespace Msp {
7 namespace IO {
8
9 /**
10 Helper class for reading data in a way that supports events.  For internal use
11 only.
12
13 On Windows, overlapped reads are used.  Data is read to an internal buffer and
14 handed out from there.  An event object is kept synchronized with the buffer
15 state to get level-triggered semantics for poll.  Whenever the buffer becomes
16 empty, a new overlapped read is started.
17
18 Unix-based systems can poll the fd directly, so this class reduces to a simple
19 passthrough to sys_read.
20 */
21 class EventReader
22 {
23 private:
24         struct Private;
25
26         Handle &handle;
27         Private *priv;
28
29 public:
30         EventReader(Handle &, unsigned);
31         ~EventReader();
32
33         const Handle &get_event();
34
35         void start();
36         void wait();
37         unsigned read(char *, unsigned);
38 };
39
40 } // namespace IO
41 } // namespace Msp
42
43 #endif