Chris@16: // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) Chris@16: // (C) Copyright 2005-2007 Jonathan Turkanis Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) Chris@16: Chris@16: // See http://www.boost.org/libs/iostreams for documentation. Chris@16: Chris@16: #ifndef BOOST_IOSTREAMS_DETAIL_NON_BLOCKING_ADAPTER_HPP_INCLUDED Chris@16: #define BOOST_IOSTREAMS_DETAIL_NON_BLOCKING_ADAPTER_HPP_INCLUDED Chris@16: Chris@16: #include // streamsize, seekdir, openmode. Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace iostreams { Chris@16: Chris@16: template Chris@16: class non_blocking_adapter { Chris@16: public: Chris@16: typedef typename char_type_of::type char_type; Chris@16: struct category Chris@16: : mode_of::type, device_tag Chris@16: { }; Chris@16: explicit non_blocking_adapter(Device& dev) : device_(dev) { } Chris@16: std::streamsize read(char_type* s, std::streamsize n) Chris@16: { Chris@16: std::streamsize result = 0; Chris@16: while (result < n) { Chris@16: std::streamsize amt = iostreams::read(device_, s, n); Chris@16: if (amt == -1) Chris@16: break; Chris@16: result += amt; Chris@16: } Chris@16: return result != 0 ? result : -1; Chris@16: } Chris@16: std::streamsize write(const char_type* s, std::streamsize n) Chris@16: { Chris@16: std::streamsize result = 0; Chris@16: while (result < n) { Chris@16: std::streamsize amt = Chris@16: iostreams::write(device_, s + result, n - result); Chris@16: result += amt; Chris@16: } Chris@16: return result; Chris@16: } Chris@16: std::streampos seek( stream_offset off, BOOST_IOS::seekdir way, Chris@16: BOOST_IOS::openmode which = Chris@16: BOOST_IOS::in | BOOST_IOS::out ) Chris@16: { return iostreams::seek(device_, off, way, which); } Chris@16: public: Chris@16: non_blocking_adapter& operator=(const non_blocking_adapter&); Chris@16: Device& device_; Chris@16: }; Chris@16: Chris@16: } } // End namespace iostreams. Chris@16: Chris@16: #endif // #ifndef BOOST_IOSTREAMS_DETAIL_NON_BLOCKING_ADAPTER_HPP_INCLUDED