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