Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
serving_request.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * foxxll/io/serving_request.cpp
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  *
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 <iomanip>
15 
18 #include <foxxll/io/file.hpp>
22 
23 namespace foxxll {
24 
26  const completion_handler& on_cmpl,
27  file* file, void* buffer, offset_type offset, size_type bytes,
28  read_or_write op)
29  : request_with_state(on_cmpl, file, buffer, offset, bytes, op)
30 {
31 #ifdef FOXXLL_CHECK_BLOCK_ALIGNING
32  // Direct I/O requires file system block size alignment for file offsets,
33  // memory buffer addresses, and transfer(buffer) size must be multiple
34  // of the file system block size
35  if (file->need_alignment())
37 #endif
38 }
39 
41 {
42  check_nref();
43  LOG << "serving_request[" << static_cast<void*>(this) << "]::serve(): " <<
44  buffer_ << " @ [" <<
45  file_ << "|" << file_->get_allocator_id() << "]0x" <<
46  std::hex << std::setfill('0') << std::setw(8) <<
47  offset_ << "/0x" << bytes_ <<
48  (op_ == request::READ ? " READ" : " WRITE");
49 
50  try
51  {
52  file_->serve(buffer_, offset_, bytes_, op_);
53  }
54  catch (const io_error& ex)
55  {
56  error_occured(ex.what());
57  }
58 
59  check_nref(true);
60 
61  completed(false);
62 }
63 
64 const char* serving_request::io_type() const
65 {
66  return file_->io_type();
67 }
68 
69 } // namespace foxxll
70 
71 /**************************************************************************/
Request with completion shared_state.
virtual int get_allocator_id() const =0
Returns the file's parallel disk block allocator number.
uint64_t offset_type
type for offsets within a file
offset_type offset_
offset within file
Definition: request.hpp:67
serving_request(const completion_handler &on_complete, file *file, void *buffer, offset_type offset, size_type bytes, read_or_write op)
virtual const char * io_type() const =0
const char * io_type() const final
Identifies the type of I/O implementation.
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
void * buffer_
data buffer to transfer
Definition: request.hpp:65
void completed(bool canceled) override
bool need_alignment() const
Returns need_alignment_.
Definition: file.hpp:204
virtual void serve(void *buffer, offset_type offset, size_type bytes, request::read_or_write op)=0
static const size_t bytes
number of bytes in uint_pair
Definition: uint_types.hpp:75
void check_alignment() const
Definition: request.cpp:40
void check_nref(bool after=false)
Definition: request.hpp:127
#define LOG
Default logging method: output if the local debug variable is true.
Definition: logger.hpp:141
void error_occured(const char *msg)
Definition: request.cpp:80
read_or_write op_
READ or WRITE.
Definition: request.hpp:71