Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
request.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * foxxll/io/request.cpp
3  *
4  * Part of FOXXLL. See http://foxxll.org
5  *
6  * Copyright (C) 2008 Andreas Beckmann <[email protected]>
7  * Copyright (C) 2009 Johannes Singler <[email protected]>
8  *
9  * Distributed under the Boost Software License, Version 1.0.
10  * (See accompanying file LICENSE_1_0.txt or copy at
11  * http://www.boost.org/LICENSE_1_0.txt)
12  **************************************************************************/
13 
14 #include <ostream>
15 
16 #include <tlx/logger/core.hpp>
17 
18 #include <foxxll/io/file.hpp>
19 #include <foxxll/io/request.hpp>
20 
21 namespace foxxll {
22 
24  const completion_handler& on_complete,
25  file* file, void* buffer, offset_type offset, size_type bytes,
26  read_or_write op)
27  : on_complete_(on_complete),
28  file_(file), buffer_(buffer), offset_(offset), bytes_(bytes),
29  op_(op)
30 {
31  TLX_LOG << "request_with_state[" << static_cast<void*>(this) << "]::request(...), ref_cnt=" << reference_count();
33 }
34 
36 {
37  TLX_LOG << "request_with_state[" << static_cast<void*>(this) << "]::~request(), ref_cnt=" << reference_count();
38 }
39 
41 {
42  if (offset_ % BlockAlignment != 0)
43  TLX_LOG1 << "Offset is not aligned: modulo " <<
45 
46  if (bytes_ % BlockAlignment != 0)
47  TLX_LOG1 << "Size is not a multiple of " <<
48  BlockAlignment << ", = " << bytes_ % BlockAlignment;
49 
50  if (size_t(buffer_) % BlockAlignment != 0)
51  TLX_LOG1 << "Buffer is not aligned: modulo " <<
52  BlockAlignment << " = " << size_t(buffer_) % BlockAlignment <<
53  " (" << buffer_ << ")";
54 }
55 
57 {
58  TLX_LOG1 << "WARNING: serious error, reference to the request is lost " <<
59  (after ? "after" : "before") << " serve()" <<
60  " nref=" << reference_count() <<
61  " this=" << this <<
62  " offset=" << offset_ <<
63  " buffer=" << buffer_ <<
64  " bytes=" << bytes_ <<
65  " op=" << ((op_ == READ) ? "READ" : "WRITE") <<
66  " file=" << file_ <<
67  " iotype=" << file_->io_type();
68 }
69 
70 std::ostream& request::print(std::ostream& out) const
71 {
72  out << "File object address: " << file_
73  << " Buffer address: " << static_cast<void*>(buffer_)
74  << " File offset: " << offset_
75  << " Transfer size: " << bytes_ << " bytes"
76  " Type of transfer: " << ((op_ == READ) ? "READ" : "WRITE");
77  return out;
78 }
79 
80 void request::error_occured(const char* msg)
81 {
82  error_.reset(new io_error(msg));
83 }
84 
86 {
87  error_.reset(new io_error(msg));
88 }
89 
90 const char* request::io_type() const
91 {
92  return file_->io_type();
93 }
94 
96 {
97  if (file_) {
99  file_ = nullptr;
100  }
101 }
102 
103 std::ostream& operator << (std::ostream& out, const request& req)
104 {
105  return req.print(out);
106 }
107 
108 } // namespace foxxll
109 
110 /**************************************************************************/
std::unique_ptr< io_error > error_
Definition: request.hpp:56
std::ostream & operator<<(std::ostream &o, const stats &s)
Definition: iostats.cpp:375
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
virtual const char * io_type() const =0
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
constexpr size_t BlockAlignment
Definition: request.hpp:34
void * buffer_
data buffer to transfer
Definition: request.hpp:65
void delete_request_ref()
decrement referenced requests
Definition: file.hpp:229
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)
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220
static const size_t bytes
number of bytes in uint_pair
Definition: uint_types.hpp:75
void release_file_reference()
Definition: request.cpp:95
void check_nref_failed(bool after)
Definition: request.cpp:56
Request object encapsulating basic properties like file and offset.
Definition: request.hpp:49
#define TLX_LOG1
Definition: core.hpp:145
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 add_request_ref()
increment referenced requests
Definition: file.hpp:223
void error_occured(const char *msg)
Definition: request.cpp:80
#define TLX_LOG
Default logging method: output if the local debug variable is true.
Definition: core.hpp:141
read_or_write op_
READ or WRITE.
Definition: request.hpp:71