AsyncIOTask.h++

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002    commonc++ - A C++ Common Class Library
00003    Copyright (C) 2005-2009  Mark A Lindner
00004 
00005    This file is part of commonc++.
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public
00018    License along with this library; if not, write to the Free
00019    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 }; // namespace ccxx
00143 
00144 #endif // __ccxx_AsyncIOTask_hxx
00145 
00146 /* end of header file */

Generated on Sat Apr 17 23:03:05 2010 for libcommonc++ by  doxygen 1.5.9