jaio.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef JAIO_INCL
  14. #define JAIO_INCL
  15. #include "jlib.hpp"
  16. #include "jmisc.hpp"
  17. #if defined (__linux__)
  18. class AsyncRequest;
  19. class jlib_decl AsyncBlockReader
  20. {
  21. public:
  22. AsyncBlockReader();
  23. ~AsyncBlockReader();
  24. void init(int file, offset_t start,size32_t blocksize,void *buf1,void *buf2);
  25. void *readnext(size32_t &ret);
  26. void getinfo(offset_t &of,offset_t &p,offset_t &sz);
  27. private:
  28. void waitblk();
  29. void enqueue(AsyncRequest *req);
  30. void finish();
  31. AsyncRequest *cur;
  32. AsyncRequest *next;
  33. size32_t blksize;
  34. offset_t offset;
  35. offset_t pos;
  36. offset_t start;
  37. offset_t insize;
  38. int infile;
  39. int eof;
  40. };
  41. #endif
  42. #ifdef _WIN32
  43. class CW32AsyncRequest; // forward reference
  44. class jlib_decl CW32AsyncBlockReader
  45. {
  46. private:
  47. OVERLAPPED overlapped; // the file io overlap control structure
  48. HANDLE hfile;
  49. CW32AsyncRequest * currentRequest, * nextRequest;
  50. bool eof, pending; // pending is true when an IO operation has been 'requested' but no yet completed
  51. C64bitComposite offset, insize;
  52. offset_t start; // offset is contained also in overlapped as hi and lo DWORDs
  53. size32_t blockSize;
  54. void enqueue(); // calls for next record
  55. DWORD waitblk(); // waits for next record, returns bytes read
  56. void finish();
  57. public:
  58. CW32AsyncBlockReader();
  59. ~CW32AsyncBlockReader();
  60. void init(HANDLE file, offset_t start, size32_t blockSize, void * buffer1, void * buffer2);
  61. void * readnext(size32_t &readLength);
  62. void reset();
  63. void getinfo(offset_t &of, offset_t &p, offset_t &sz);
  64. };
  65. #endif // _WIN32
  66. #endif