libcommonc++  0.7
AsyncIOTask.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_AsyncIOTask_hxx
24 #define __ccxx_AsyncIOTask_hxx
25 
26 #include <commonc++/Common.h++>
27 
28 #include <commonc++/Buffer.h++>
31 
32 #ifdef CCXX_OS_POSIX
33 struct aiocb;
34 #endif
35 
36 namespace ccxx {
37 
44 {
45  friend class Stream;
46  friend class AsyncIOPoller;
47 
48  public:
49 
59  AsyncIOTask();
60 
62  ~AsyncIOTask();
63 
77  bool isCompleted();
78 
88  void cancel();
89 
99  void waitFor(timespan_ms_t timeout);
100 
110  size_t getBytesTransferred();
111 
112  private:
113 
114  void init(FileHandle file, int64_t offset, byte_t* buf, size_t buflen);
115  void init(FileHandle file, int64_t offset, ByteBuffer* buf);
116 
117  void _init(FileHandle file, int64_t offset, byte_t* buf, size_t buflen);
118 
119  void _collectResult();
120 
121  inline void setPending(bool pending)
122  { _pending = pending; }
123 
124  inline FileHandle getFileHandle()
125  { return(_file); }
126 
127 #if defined(CCXX_OS_WINDOWS)
128  inline LPOVERLAPPED getControlBlock()
129  { return(&_overlapped); }
130 #elif !defined(CCXX_OS_ANDROID)
131  inline struct aiocb *getControlBlock()
132  { return (_aiocb); }
133 #endif
134 
135  FileHandle _file;
136  size_t _result;
137  bool _pending;
138  bool _haveResult;
139  ByteBuffer* _buffer;
140 #if defined(CCXX_OS_WINDOWS)
141  DWORD _length;
142  mutable OVERLAPPED _overlapped;
143 #elif !defined(CCXX_OS_ANDROID)
144  mutable struct aiocb* _aiocb;
145 #endif
146 };
147 
148 } // namespace ccxx
149 
150 #endif // __ccxx_AsyncIOTask_hxx
An unbuffered I/O stream.
Definition: Stream.h++:60
A class that polls a set of AsyncIOTask objects.
Definition: AsyncIOPoller.h++:35
int FileHandle
Definition: Common.h++:225
#define COMMONCPP_API
Definition: Common.h++:126
A buffer for storing a contiguous sequence of elements.
Definition: Buffer.h++:44
int timespan_ms_t
A timespan expressed in milliseconds.
Definition: Integers.h++:104
Definition: AllocationMap.c++:25
An object representing an asynchronous I/O operation.
Definition: AsyncIOTask.h++:43
unsigned char byte_t
An unsigned 8-bit value.
Definition: Integers.h++:68