29 #ifndef Pt_System_IODevice_h
30 #define Pt_System_IODevice_h
32 #include <Pt/System/Api.h>
33 #include <Pt/System/IOError.h>
34 #include <Pt/System/Selectable.h>
36 #include <Pt/Signal.h>
58 typedef std::char_traits<char>::pos_type pos_type;
59 typedef std::char_traits<char>::off_type off_type;
60 typedef std::ios_base::seekdir seekdir;
72 void setTimeout(std::size_t timeout);
76 void beginRead(
char* buffer, std::size_t n);
80 std::size_t endRead();
94 std::size_t read(
char* buffer, std::size_t n);
98 void beginWrite(
const char* buffer, std::size_t n);
102 std::size_t endWrite();
112 std::size_t write(
const char* buffer, std::size_t n);
116 bool seekable()
const;
122 pos_type seek(off_type offset, seekdir sd);
129 std::size_t peek(
char* buffer, std::size_t n);
159 {
return _inputReady; }
168 {
return _outputReady; }
173 {
return _rbuf != 0; }
178 {
return _wbuf != 0; }
183 std::size_t rbuflen()
const
186 std::size_t ravail()
const
189 const char* wbuf()
const
192 std::size_t wbuflen()
const
195 std::size_t wavail()
const
207 virtual void onClose() = 0;
209 virtual void onSetTimeout(std::size_t timeout) = 0;
211 virtual std::size_t onBeginRead(
EventLoop& loop,
char* buffer, std::size_t n,
bool& eof) = 0;
213 virtual std::size_t onEndRead(
EventLoop& loop,
char* buffer, std::size_t n,
bool& eof) = 0;
215 virtual std::size_t onRead(
char* buffer, std::size_t count,
bool& eof) = 0;
217 virtual std::size_t onBeginWrite(
EventLoop& loop,
const char* buffer, std::size_t n) = 0;
219 virtual std::size_t onEndWrite(
EventLoop& loop,
const char* buffer, std::size_t n) = 0;
221 virtual std::size_t onWrite(
const char* buffer, std::size_t count) = 0;
223 virtual std::size_t onPeek(
char* buffer, std::size_t)
226 virtual bool onSeekable()
const
229 virtual pos_type onSeek(off_type, std::ios::seekdir)
230 {
throw IOError(
"Could not seek on device"); }
232 virtual void onSync()
const
235 void setEof(
bool eof);
237 virtual void onAttach(EventLoop& loop);
239 virtual void onDetach(EventLoop& loop);
241 virtual void onCancel();
246 std::size_t _rbuflen;
249 std::size_t _wbuflen;
251 Signal<IODevice&> _inputReady;
252 Signal<IODevice&> _outputReady;
253 Pt::varint_t _reserved;
263 #endif // Pt_System_IODevice_h
EventLoop * loop() const
Returns the used event loop.
Definition: IODevice.h:200
Dispatches operations through an event loop.
Definition: Selectable.h:44
Multicast Signal to call multiple slots.
Definition: Signal.h:109
Endpoint for I/O operations.
Definition: IODevice.h:55
bool isReading() const
Returns true if the device is reading.
Definition: IODevice.h:172
Signal< IODevice & > & inputReady()
Notifies about available data.
Definition: IODevice.h:158
Thread-safe event loop supporting I/O multiplexing and Timers.
Definition: EventLoop.h:72
Signal< IODevice & > & outputReady()
Notifies when data can be written.
Definition: IODevice.h:167
bool isWriting() const
Returns true if the device is writing.
Definition: IODevice.h:177