STXXL  1.4.0
 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 
25 
27 
28 serving_request::serving_request(
29  const completion_handler& on_cmpl,
30  file* f,
31  void* buf,
32  offset_type off,
33  size_type b,
34  request_type t) :
35  request_with_state(on_cmpl, f, buf, off, b, t)
36 {
37 #ifdef STXXL_CHECK_BLOCK_ALIGNING
38  // Direct I/O requires file system block size alignment for file offsets,
39  // memory buffer addresses, and transfer(buffer) size must be multiple
40  // of the file system block size
42 #endif
43 }
44 
46 {
47  check_nref();
49  "[" << static_cast<void*>(this) << "] serving_request::serve(): " <<
50  buffer << " @ [" <<
51  file_ << "|" << file_->get_allocator_id() << "]0x" <<
52  std::hex << std::setfill('0') << std::setw(8) <<
53  offset << "/0x" << bytes <<
54  ((type == request::READ) ? " READ" : " WRITE"));
55 
56  try
57  {
58  file_->serve(this);
59  }
60  catch (const io_error& ex)
61  {
62  error_occured(ex.what());
63  }
64 
65  check_nref(true);
66 
67  completed();
68 }
69 
71 {
72  STXXL_VERBOSE2("[" << static_cast<void*>(this) << "] serving_request::completed()");
76 }
77 
78 const char* serving_request::io_type() const
79 {
80  return file_->io_type();
81 }
82 
84 // vim: et:ts=4:sw=4
virtual void serve(const request *req)=0
void set_to(const value_type &new_state)
Definition: state.h:44
offset_type offset
Definition: request.h:48
Completion handler class (Loki-style).
state< request_state > _state
request_type type
Definition: request.h:50
Request with completion state.
#define STXXL_VERBOSE2(x)
Definition: verbose.h:107
void completed()
Definition: request.cpp:44
const char * io_type() const
Identifies the type of I/O implementation.
Defines interface of file.
Definition: file.h:52
void check_nref(bool after=false)
Definition: request.h:96
void check_alignment() const
Definition: request.cpp:52
size_type bytes
Definition: request.h:49
virtual const char * io_type() const
Identifies the type of I/O implementation.
Definition: file.h:181
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
stxxl::internal_size_type size_type
file * file_
Definition: request.h:46
virtual int get_allocator_id() const =0
Returns the file&#39;s allocator.
void * buffer
Definition: request.h:47
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:76
#define STXXL_END_NAMESPACE
Definition: namespace.h:17