Thrill  0.1
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  TLX_LOG
44  << "serving_request[" << static_cast<void*>(this) << "]::serve(): "
45  << buffer_ << " @ ["
46  << file_ << "|" << file_->get_allocator_id() << "]0x"
47  << std::hex << std::setfill('0') << std::setw(8)
48  << offset_ << "/0x" << bytes_
49  << (op_ == request::READ ? " READ" : " WRITE");
50 
51  try
52  {
53  file_->serve(buffer_, offset_, bytes_, op_);
54  }
55  catch (const io_error& ex)
56  {
57  error_occured(ex.what());
58  }
59 
60  check_nref(true);
61 
62  completed(false);
63 }
64 
65 const char* serving_request::io_type() const
66 {
67  return file_->io_type();
68 }
69 
70 } // namespace foxxll
71 
72 /**************************************************************************/
Request with completion shared_state.
virtual int get_allocator_id() const =0
Returns the file&#39;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
virtual void serve(void *buffer, offset_type offset, size_type bytes, request::read_or_write op)=0
FOXXLL library namespace
static const size_t bytes
number of bytes in uint_pair
Definition: uint_types.hpp:75
void check_alignment() const
Definition: request.cpp:40
bool need_alignment() const
Returns need_alignment_.
Definition: file.hpp:204
void check_nref(bool after=false)
Definition: request.hpp:127
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