Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
request.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * foxxll/io/request.hpp
3  *
4  * Part of FOXXLL. See http://foxxll.org
5  *
6  * Copyright (C) 2002 Roman Dementiev <[email protected]>
7  * Copyright (C) 2008 Andreas Beckmann <[email protected]>
8  * Copyright (C) 2013-2014 Timo Bingmann <[email protected]>
9  *
10  * Distributed under the Boost Software License, Version 1.0.
11  * (See accompanying file LICENSE_1_0.txt or copy at
12  * http://www.boost.org/LICENSE_1_0.txt)
13  **************************************************************************/
14 
15 #ifndef FOXXLL_IO_REQUEST_HEADER
16 #define FOXXLL_IO_REQUEST_HEADER
17 
18 #include <cassert>
19 #include <functional>
20 #include <memory>
21 #include <string>
22 
23 #include <tlx/counting_ptr.hpp>
24 #include <tlx/delegate.hpp>
25 
28 
29 namespace foxxll {
30 
31 //! \addtogroup foxxll_reqlayer
32 //! \{
33 
34 constexpr size_t BlockAlignment = 4096;
35 
36 class file;
37 class request;
38 
39 //! A reference counting pointer for \c file.
41 
42 //! A reference counting pointer for \c request.
44 
45 //! completion handler
47 
48 //! Request object encapsulating basic properties like file and offset.
49 class request : virtual public request_interface, public tlx::reference_counter
50 {
51  constexpr static bool debug = false;
52  friend class linuxaio_queue;
53 
54 protected:
56  std::unique_ptr<io_error> error_;
57 
58 protected:
59  //! \name Base Parameter of an I/O Request
60  //! \{
61 
62  //! file implementation to perform I/O with
64  //! data buffer to transfer
65  void* buffer_;
66  //! offset within file
68  //! number of bytes at buffer_ to transfer
70  //! READ or WRITE
72 
73  //! \}
74 
75 public:
76  request(const completion_handler& on_complete,
79 
80  //! non-copyable: delete copy-constructor
81  request(const request&) = delete;
82  //! non-copyable: delete assignment operator
83  request& operator = (const request&) = delete;
84  //! move-constructor: default
85  request(request&&) = default;
86  //! move-assignment operator: default
87  request& operator = (request&&) = default;
88 
89  virtual ~request();
90 
91 public:
92  //! \name Accessors
93  //! \{
94 
95  file * get_file() const { return file_; }
96  void * buffer() const { return buffer_; }
97  offset_type offset() const { return offset_; }
98  size_type bytes() const { return bytes_; }
99  read_or_write op() const { return op_; }
100 
101  void check_alignment() const;
102 
103  std::ostream & print(std::ostream& out) const final;
104 
105  //! Inform the request object that an error occurred during the I/O
106  //! execution.
107  void error_occured(const char* msg);
108 
109  //! Inform the request object that an error occurred during the I/O
110  //! execution.
111  void error_occured(const std::string& msg);
112 
113  //! Rises an exception if there were error with the I/O.
115  {
116  if (error_.get())
117  throw *(error_.get());
118  }
119 
120  const char * io_type() const override;
121 
122  void release_file_reference();
123 
124  //! \}
125 
126 protected:
127  void check_nref(bool after = false)
128  {
129  if (reference_count() < 2)
130  check_nref_failed(after);
131  }
132 
133 private:
134  void check_nref_failed(bool after);
135 };
136 
137 std::ostream& operator << (std::ostream& out, const request& req);
138 
139 //! \}
140 
141 } // namespace foxxll
142 
143 #endif // !FOXXLL_IO_REQUEST_HEADER
144 
145 /**************************************************************************/
void * buffer() const
Definition: request.hpp:96
uint64_t offset_type
type for offsets within a file
friend class linuxaio_queue
Definition: request.hpp:52
std::unique_ptr< io_error > error_
Definition: request.hpp:56
std::ostream & operator<<(std::ostream &o, const stats &s)
Definition: iostats.cpp:374
static constexpr bool debug
Definition: request.hpp:51
offset_type offset_
offset within file
Definition: request.hpp:67
request(const completion_handler &on_complete, file *file, void *buffer, offset_type offset, size_type bytes, read_or_write op)
Definition: request.cpp:23
file * file_
file implementation to perform I/O with
Definition: request.hpp:63
size_type bytes_
number of bytes at buffer_ to transfer
Definition: request.hpp:69
size_t size_type
type for block transfer sizes
read_or_write op() const
Definition: request.hpp:99
constexpr size_t BlockAlignment
Definition: request.hpp:34
void * buffer_
data buffer to transfer
Definition: request.hpp:65
void check_errors()
Rises an exception if there were error with the I/O.
Definition: request.hpp:114
const char * io_type() const override
Identifies the type of I/O implementation.
Definition: request.cpp:90
virtual ~request()
Definition: request.cpp:35
size_t reference_count() const noexcept
Return the number of references to this object (for debugging)
size_type bytes() const
Definition: request.hpp:98
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220
High-performance smart pointer used as a wrapping reference counting pointer.
completion_handler on_complete_
Definition: request.hpp:55
void release_file_reference()
Definition: request.cpp:95
void check_nref_failed(bool after)
Definition: request.cpp:56
file * get_file() const
Definition: request.hpp:95
offset_type offset() const
Definition: request.hpp:97
request & operator=(const request &)=delete
non-copyable: delete assignment operator
Request object encapsulating basic properties like file and offset.
Definition: request.hpp:49
std::ostream & print(std::ostream &out) const final
Dumps properties of a request.
Definition: request.cpp:70
void check_alignment() const
Definition: request.cpp:40
void check_nref(bool after=false)
Definition: request.hpp:127
Provides reference counting abilities for use with CountingPtr.
void error_occured(const char *msg)
Definition: request.cpp:80
read_or_write op_
READ or WRITE.
Definition: request.hpp:71