1
// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2
// (C) Copyright 2005-2007 Jonathan Turkanis
3
// Distributed under the Boost Software License, Version 1.0. (See accompanying
4
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
6
// See http://www.boost.org/libs/iostreams for documentation.
8
#ifndef BOOST_IOSTREAMS_DETAIL_NON_BLOCKING_ADAPTER_HPP_INCLUDED
9
#define BOOST_IOSTREAMS_DETAIL_NON_BLOCKING_ADAPTER_HPP_INCLUDED
11
#include <boost/iostreams/detail/ios.hpp> // streamsize, seekdir, openmode.
12
#include <boost/iostreams/read.hpp>
13
#include <boost/iostreams/seek.hpp>
14
#include <boost/iostreams/traits.hpp>
15
#include <boost/iostreams/write.hpp>
17
namespace boost { namespace iostreams {
19
template<typename Device>
20
class non_blocking_adapter {
22
typedef typename char_type_of<Device>::type char_type;
24
: mode_of<Device>::type, device_tag
26
explicit non_blocking_adapter(Device& dev) : device_(dev) { }
27
std::streamsize read(char_type* s, std::streamsize n)
29
std::streamsize result = 0;
31
std::streamsize amt = iostreams::read(device_, s, n);
36
return result != 0 ? result : -1;
38
std::streamsize write(const char_type* s, std::streamsize n)
40
std::streamsize result = 0;
43
iostreams::write(device_, s + result, n - result);
48
std::streampos seek( stream_offset off, BOOST_IOS::seekdir way,
49
BOOST_IOS::openmode which =
50
BOOST_IOS::in | BOOST_IOS::out )
51
{ return iostreams::seek(device_, off, way, which); }
53
non_blocking_adapter& operator=(const non_blocking_adapter&);
57
} } // End namespace iostreams.
59
#endif // #ifndef BOOST_IOSTREAMS_DETAIL_NON_BLOCKING_ADAPTER_HPP_INCLUDED