• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Directories
  • File List
  • File Members

basic_socketbuf.hpp

Go to the documentation of this file.
00001 /*
00002   CLAW - a C++ Library Absolutely Wonderful
00003 
00004   CLAW is a free library without any particular aim but being useful to 
00005   anyone.
00006 
00007   Copyright (C) 2005-2010 Julien Jorge
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023   contact: julien_jorge@yahoo.fr
00024 */
00031 #ifndef __CLAW_BASIC_SOCKETBUF_HPP__
00032 #define __CLAW_BASIC_SOCKETBUF_HPP__
00033 
00034 #include <streambuf>
00035 #include <string>
00036 #include <claw/basic_socket.hpp>
00037 
00038 namespace claw
00039 {
00040   namespace net
00041   {
00047     template< typename CharT, typename Traits >
00048     class basic_socketbuf : private basic_socket,
00049                             public std::basic_streambuf<CharT, Traits>
00050     {
00051     public:
00052       typedef CharT                          char_type;
00053       typedef Traits                         traits_type;
00054       typedef typename traits_type::int_type int_type;
00055       typedef typename traits_type::pos_type pos_type;
00056       typedef typename traits_type::off_type off_type;
00057 
00058       typedef basic_socketbuf<char_type, traits_type> self_type;
00059 
00060     public:
00061       basic_socketbuf( int read_limit = -1 );
00062       virtual ~basic_socketbuf();
00063 
00064       self_type* open( const std::string& addr, int port );
00065       self_type* open( socket_traits::descriptor d );
00066       self_type* close();
00067 
00068       bool is_open() const;
00069 
00070       void set_read_time_limit( int read_limit );
00071 
00072     protected:
00073       virtual int sync();
00074       virtual int_type underflow();
00075       virtual int_type overflow( int_type c = traits_type::eof() );
00076 
00077     private:
00078       bool connect( const std::string& addr, int port );
00079 
00080       void create_buffers();
00081       void destroy_buffers();
00082 
00083       bool buffered() const;
00084 
00085     private:
00088       int m_read_limit;
00089 
00091       char_type* m_input_buffer;
00092 
00094       size_t m_input_buffer_size;
00095 
00097       char_type* m_output_buffer;
00098 
00100       size_t m_output_buffer_size;
00101 
00103       static const size_t s_buffer_size;
00104 
00105     }; // class basic_socketbuf
00106   } // namespace net
00107 } // namespace claw
00108 
00109 #include <claw/impl/basic_socketbuf.tpp>
00110 
00111 #endif // __CLAW_BASIC_SOCKETBUF_HPP__

Generated on Fri Dec 24 2010 13:18:31 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.7.2