Stxxl  1.4.0
io/serving_request.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *  io/serving_request.cpp
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2002 Roman Dementiev <dementiev@mpi-sb.mpg.de>
00007  *  Copyright (C) 2008 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
00008  *
00009  *  Distributed under the Boost Software License, Version 1.0.
00010  *  (See accompanying file LICENSE_1_0.txt or copy at
00011  *  http://www.boost.org/LICENSE_1_0.txt)
00012  **************************************************************************/
00013 
00014 #include <iomanip>
00015 #include <stxxl/bits/io/serving_request.h>
00016 #include <stxxl/bits/io/file.h>
00017 
00018 
00019 __STXXL_BEGIN_NAMESPACE
00020 
00021 
00022 serving_request::serving_request(
00023     const completion_handler & on_cmpl,
00024     file * f,
00025     void * buf,
00026     offset_type off,
00027     size_type b,
00028     request_type t) :
00029     request_with_state(on_cmpl, f, buf, off, b, t)
00030 {
00031 #ifdef STXXL_CHECK_BLOCK_ALIGNING
00032     // Direct I/O requires file system block size alignment for file offsets,
00033     // memory buffer addresses, and transfer(buffer) size must be multiple
00034     // of the file system block size
00035     check_alignment();
00036 #endif
00037 }
00038 
00039 void serving_request::serve()
00040 {
00041     check_nref();
00042     STXXL_VERBOSE2(
00043         "[" << static_cast<void *>(this) << "] serving_request::serve(): " <<
00044         buffer << " @ [" <<
00045         file_ << "|" << file_->get_allocator_id() << "]0x" <<
00046         std::hex << std::setfill('0') << std::setw(8) <<
00047         offset << "/0x" << bytes <<
00048         ((type == request::READ) ? " READ" : " WRITE"));
00049 
00050     try
00051     {
00052         file_->serve(this);
00053     }
00054     catch (const io_error & ex)
00055     {
00056         error_occured(ex.what());
00057     }
00058 
00059     check_nref(true);
00060 
00061     completed();
00062 }
00063 
00064 void serving_request::completed()
00065 {
00066     STXXL_VERBOSE2("[" << static_cast<void *>(this) << "] serving_request::completed()");
00067     _state.set_to(DONE);
00068     request_with_state::completed();
00069     _state.set_to(READY2DIE);
00070 }
00071 
00072 const char * serving_request::io_type() const
00073 {
00074     return file_->io_type();
00075 }
00076 
00077 __STXXL_END_NAMESPACE
00078 // vim: et:ts=4:sw=4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines