AsyncIOTask.h++
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __ccxx_AsyncIOTask_hxx
00024 #define __ccxx_AsyncIOTask_hxx
00025
00026 #include <commonc++/Common.h++>
00027 #include <commonc++/Buffer.h++>
00028 #include <commonc++/IOException.h++>
00029 #include <commonc++/InterruptedException.h++>
00030
00031 #ifdef CCXX_OS_POSIX
00032 #include <aio.h>
00033 #endif
00034
00035 namespace ccxx {
00036
00042 class COMMONCPP_API AsyncIOTask
00043 {
00044 friend class Stream;
00045 friend class AsyncIOPoller;
00046
00047 public:
00048
00057 AsyncIOTask();
00058
00060 ~AsyncIOTask();
00061
00074 bool isCompleted() throw(IOException, InterruptedException);
00075
00084 void cancel() throw(IOException);
00085
00094 void waitFor(uint_t timeout) throw(IOException, InterruptedException);
00095
00104 size_t getBytesTransferred() throw();
00105
00106 private:
00107
00108 void init(FileHandle file, int64_t offset, byte_t *buf, size_t buflen);
00109 void init(FileHandle file, int64_t offset, ByteBuffer *buf);
00110
00111 void _init(FileHandle file, int64_t offset, byte_t *buf, size_t buflen);
00112
00113 void _collectResult() throw(IOException, InterruptedException);
00114
00115 inline void setPending(bool pending)
00116 { _pending = pending; }
00117
00118 inline FileHandle getFileHandle() throw()
00119 { return(_file); }
00120
00121 #ifdef CCXX_OS_WINDOWS
00122 inline LPOVERLAPPED getControlBlock() throw()
00123 { return(&_overlapped); }
00124 #else
00125 inline struct aiocb *getControlBlock() throw()
00126 { return (&_aiocb); }
00127 #endif
00128
00129 FileHandle _file;
00130 size_t _result;
00131 bool _pending;
00132 bool _haveResult;
00133 ByteBuffer *_buffer;
00134 #ifdef CCXX_OS_WINDOWS
00135 DWORD _length;
00136 mutable OVERLAPPED _overlapped;
00137 #else
00138 mutable struct aiocb _aiocb;
00139 #endif
00140 };
00141
00142 };
00143
00144 #endif // __ccxx_AsyncIOTask_hxx
00145
00146