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>
98 typedef std::char_traits<char>::pos_type pos_type;
99 typedef std::char_traits<char>::off_type off_type;
100 typedef std::ios_base::seekdir seekdir;
134 std::size_t
read(
char* buffer, std::size_t n);
152 std::size_t
write(
const char* buffer, std::size_t n);
162 pos_type
seek(off_type offset, seekdir sd);
169 std::size_t
peek(
char* buffer, std::size_t n);
199 {
return _inputReady; }
208 {
return _outputReady; }
213 {
return _rbuf != 0; }
218 {
return _wbuf != 0; }
223 std::size_t rbuflen()
const
226 std::size_t ravail()
const
229 const char* wbuf()
const
232 std::size_t wbuflen()
const
235 std::size_t wavail()
const
247 virtual void onClose() = 0;
249 virtual void onSetTimeout(std::size_t timeout) = 0;
251 virtual std::size_t onBeginRead(
EventLoop&
loop,
char* buffer, std::size_t n,
bool& eof) = 0;
253 virtual std::size_t onEndRead(
EventLoop&
loop,
char* buffer, std::size_t n,
bool& eof) = 0;
255 virtual std::size_t onRead(
char* buffer, std::size_t count,
bool& eof) = 0;
257 virtual std::size_t onBeginWrite(
EventLoop&
loop,
const char* buffer, std::size_t n) = 0;
259 virtual std::size_t onEndWrite(
EventLoop&
loop,
const char* buffer, std::size_t n) = 0;
261 virtual std::size_t onWrite(
const char* buffer, std::size_t count) = 0;
263 virtual std::size_t onPeek(
char*, std::size_t)
266 virtual bool onSeekable()
const
269 virtual pos_type onSeek(off_type, std::ios::seekdir)
270 {
throw IOError(
"Could not seek on device"); }
272 virtual void onSync()
const
275 void setEof(
bool eof);
281 std::size_t _rbuflen;
284 std::size_t _wbuflen;
288 Pt::varint_t _reserved;
I/O error.
Definition IOError.h:44
Multicast Signal to call multiple slots.
Definition Signal.h:190
Event loop of a thread or process.
Definition EventLoop.h:83
void beginWrite(const char *buffer, std::size_t n)
Begins to write data.
std::size_t endRead()
Ends reading data.
bool isWriting() const
Returns true if the device is writing.
Definition IODevice.h:217
bool isEof() const
Returns if the device has reached EOF.
virtual void onCancel()
Blocks until operation has cancelled.
void setTimeout(std::size_t timeout)
Sets the timeout for blocking I/O in milliseconds.
void close()
Closes the device.
std::size_t endWrite()
Ends writing data.
std::size_t write(const char *buffer, std::size_t n)
Write data to I/O device.
pos_type seek(off_type offset, seekdir sd)
Moves the read position to the given offset.
virtual ~IODevice()
Destructor.
IODevice()
Default Constructor.
std::size_t peek(char *buffer, std::size_t n)
Peek data from I/O device without consuming them.
std::size_t read(char *buffer, std::size_t n)
Read data from I/O device.
pos_type position()
Returns the current I/O position.
bool seekable() const
Returns true if device is seekable.
void beginRead(char *buffer, std::size_t n)
Begins to read data.
bool isReading() const
Returns true if the device is reading.
Definition IODevice.h:212
void sync()
Synchronize device.
EventLoop * loop() const
Returns the used event loop.
Definition IODevice.h:240
Signal< IODevice & > & outputReady()
Notifies when data can be written.
Definition IODevice.h:207
Signal< IODevice & > & inputReady()
Notifies about available data.
Definition IODevice.h:198
Selectable()
Default Constructor.
EventLoop * parent() const
Returns the used event loop.
Definition Selectable.h:80
System programming
Definition Connection.h:26
Core module.
Definition Allocator.h:33