BVB Source Codes

mars Show non_blocking_adapter.hpp Source code

Return Download mars: download non_blocking_adapter.hpp Source code - Download mars Source code - Type:.hpp
  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.)
  5.  
  6. // See http://www.boost.org/libs/iostreams for documentation.
  7.  
  8. #ifndef BOOST_IOSTREAMS_DETAIL_NON_BLOCKING_ADAPTER_HPP_INCLUDED
  9. #define BOOST_IOSTREAMS_DETAIL_NON_BLOCKING_ADAPTER_HPP_INCLUDED
  10.  
  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>
  16.  
  17. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost { namespace iostreams {
  18.  
  19. template<typename Device>
  20. class non_blocking_adapter {
  21. public:
  22.     typedef typename char_type_of<Device>::type char_type;
  23.     struct category
  24.         : mode_of<Device>::type, device_tag
  25.         { };
  26.     explicit non_blocking_adapter(Device& dev) : device_(dev) { }
  27.     std::streamsize read(char_type* s, std::streamsize n)
  28.     {
  29.         std::streamsize result = 0;
  30.         while (result < n) {
  31.             std::streamsize amt = iostreams::read(device_, s, n);
  32.             if (amt == -1)
  33.                 break;
  34.             result += amt;
  35.         }
  36.         return result != 0 ? result : -1;
  37.     }
  38.     std::streamsize write(const char_type* s, std::streamsize n)
  39.     {
  40.         std::streamsize result = 0;
  41.         while (result < n) {
  42.             std::streamsize amt =
  43.                 iostreams::write(device_, s + result, n - result);
  44.             result += amt;
  45.         }
  46.         return result;    
  47.     }
  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); }
  52. public:
  53.     non_blocking_adapter& operator=(const non_blocking_adapter&);
  54.     Device& device_;
  55. };
  56.  
  57. } } // End namespace iostreams.
  58.  
  59. #endif // #ifndef BOOST_IOSTREAMS_DETAIL_NON_BLOCKING_ADAPTER_HPP_INCLUDED
  60.  
downloadnon_blocking_adapter.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top