Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:48

0001 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
0002 // (C) Copyright 2005-2007 Jonathan Turkanis
0003 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
0005 
0006 // See http://www.boost.org/libs/iostreams for documentation.
0007 
0008 #ifndef BOOST_IOSTREAMS_DETAIL_NON_BLOCKING_ADAPTER_HPP_INCLUDED
0009 #define BOOST_IOSTREAMS_DETAIL_NON_BLOCKING_ADAPTER_HPP_INCLUDED
0010 
0011 #include <boost/iostreams/detail/ios.hpp>  // streamsize, seekdir, openmode.
0012 #include <boost/iostreams/read.hpp>
0013 #include <boost/iostreams/seek.hpp>
0014 #include <boost/iostreams/traits.hpp>
0015 #include <boost/iostreams/write.hpp>
0016 
0017 namespace boost { namespace iostreams {
0018 
0019 template<typename Device>
0020 class non_blocking_adapter {
0021 public:
0022     typedef typename char_type_of<Device>::type char_type;
0023     struct category
0024         : mode_of<Device>::type, device_tag
0025         { };
0026     explicit non_blocking_adapter(Device& dev) : device_(dev) { }
0027     std::streamsize read(char_type* s, std::streamsize n)
0028     { 
0029         std::streamsize result = 0;
0030         while (result < n) {
0031             std::streamsize amt = iostreams::read(device_, s + result, n - result);
0032             if (amt == -1)
0033                 break;
0034             result += amt;
0035         }
0036         return result != 0 ? result : -1;
0037     }
0038     std::streamsize write(const char_type* s, std::streamsize n)
0039     { 
0040         std::streamsize result = 0;
0041         while (result < n) {
0042             std::streamsize amt = 
0043                 iostreams::write(device_, s + result, n - result);
0044             // write errors, like EOF on read, need to be handled.
0045             if (amt == -1)
0046                 break;
0047             result += amt;
0048         }
0049         return result;    
0050     }
0051     std::streampos seek( stream_offset off, BOOST_IOS::seekdir way,
0052                          BOOST_IOS::openmode which = 
0053                              BOOST_IOS::in | BOOST_IOS::out )
0054     { return iostreams::seek(device_, off, way, which); }
0055 public:
0056     non_blocking_adapter& operator=(const non_blocking_adapter&);
0057     Device& device_;
0058 };
0059 
0060 } } // End namespace iostreams.
0061 
0062 #endif // #ifndef BOOST_IOSTREAMS_DETAIL_NON_BLOCKING_ADAPTER_HPP_INCLUDED