STXXL  1.4-dev
 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  * lib/io/serving_request.cpp
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
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 
16 #include <stxxl/bits/io/file.h>
20 #include <stxxl/bits/namespace.h>
21 #include <stxxl/bits/verbose.h>
22 
23 #include <iomanip>
24 
26 
27 serving_request::serving_request(
28  const completion_handler& on_cmpl,
29  file* f,
30  void* buf,
31  offset_type off,
32  size_type b,
33  request_type t)
34  : request_with_state(on_cmpl, f, buf, off, b, t)
35 {
36 #ifdef STXXL_CHECK_BLOCK_ALIGNING
37  // Direct I/O requires file system block size alignment for file offsets,
38  // memory buffer addresses, and transfer(buffer) size must be multiple
39  // of the file system block size
41 #endif
42 }
43 
45 {
46  check_nref();
48  "serving_request::serve(): " <<
49  m_buffer << " @ [" <<
50  m_file << "|" << m_file->get_allocator_id() << "]0x" <<
51  std::hex << std::setfill('0') << std::setw(8) <<
52  m_offset << "/0x" << m_bytes <<
53  ((m_type == request::READ) ? " READ" : " WRITE"));
54 
55  try
56  {
57  m_file->serve(m_buffer, m_offset, m_bytes, m_type);
58  }
59  catch (const io_error& ex)
60  {
61  error_occured(ex.what());
62  }
63 
64  check_nref(true);
65 
66  completed(false);
67 }
68 
69 const char* serving_request::io_type() const
70 {
71  return m_file->io_type();
72 }
73 
75 // vim: et:ts=4:sw=4
void completed(bool canceled)
Completion handler class (Loki-style).
request_type m_type
Definition: request.h:51
Request with completion state.
void * m_buffer
Definition: request.h:48
file * m_file
Definition: request.h:47
#define STXXL_VERBOSE2_THIS(x)
Definition: verbose.h:139
const char * io_type() const
Identifies the type of I/O implementation.
Defines interface of file.
Definition: file.h:56
void check_nref(bool after=false)
Definition: request.h:97
void check_alignment() const
Definition: request.cpp:44
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
size_type m_bytes
Definition: request.h:50
virtual void serve(void *buffer, offset_type offset, size_type bytes, request::request_type type)=0
stxxl::internal_size_type size_type
virtual int get_allocator_id() const =0
Returns the file&#39;s disk allocator number.
stxxl::external_size_type offset_type
void error_occured(const char *msg)
Inform the request object that an error occurred during the I/O execution.
Definition: request.h:75
offset_type m_offset
Definition: request.h:49
virtual const char * io_type() const =0
Identifies the type of I/O implementation.
#define STXXL_END_NAMESPACE
Definition: namespace.h:17