File: serving_request.cpp

package info (click to toggle)
libstxxl 1.4.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,476 kB
  • sloc: cpp: 45,101; ansic: 4,071; perl: 610; sh: 555; xml: 174; makefile: 18
file content (75 lines) | stat: -rw-r--r-- 2,065 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/***************************************************************************
 *  lib/io/serving_request.cpp
 *
 *  Part of the STXXL. See http://stxxl.sourceforge.net
 *
 *  Copyright (C) 2002 Roman Dementiev <dementiev@mpi-sb.mpg.de>
 *  Copyright (C) 2008 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
 *
 *  Distributed under the Boost Software License, Version 1.0.
 *  (See accompanying file LICENSE_1_0.txt or copy at
 *  http://www.boost.org/LICENSE_1_0.txt)
 **************************************************************************/

#include <stxxl/bits/common/exceptions.h>
#include <stxxl/bits/common/state.h>
#include <stxxl/bits/io/file.h>
#include <stxxl/bits/io/request_interface.h>
#include <stxxl/bits/io/request_with_state.h>
#include <stxxl/bits/io/serving_request.h>
#include <stxxl/bits/namespace.h>
#include <stxxl/bits/verbose.h>

#include <iomanip>

STXXL_BEGIN_NAMESPACE

serving_request::serving_request(
    const completion_handler& on_cmpl,
    file* f,
    void* buf,
    offset_type off,
    size_type b,
    request_type t)
    : request_with_state(on_cmpl, f, buf, off, b, t)
{
#ifdef STXXL_CHECK_BLOCK_ALIGNING
    // Direct I/O requires file system block size alignment for file offsets,
    // memory buffer addresses, and transfer(buffer) size must be multiple
    // of the file system block size
    check_alignment();
#endif
}

void serving_request::serve()
{
    check_nref();
    STXXL_VERBOSE2_THIS(
        "serving_request::serve(): " <<
        m_buffer << " @ [" <<
        m_file << "|" << m_file->get_allocator_id() << "]0x" <<
        std::hex << std::setfill('0') << std::setw(8) <<
        m_offset << "/0x" << m_bytes <<
        ((m_type == request::READ) ? " READ" : " WRITE"));

    try
    {
        m_file->serve(m_buffer, m_offset, m_bytes, m_type);
    }
    catch (const io_error& ex)
    {
        error_occured(ex.what());
    }

    check_nref(true);

    completed(false);
}

const char* serving_request::io_type() const
{
    return m_file->io_type();
}

STXXL_END_NAMESPACE
// vim: et:ts=4:sw=4