Claw  1.7.3
basic_socketbuf.hpp
Go to the documentation of this file.
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  contact: julien.jorge@gamned.org
24 */
31 #ifndef __CLAW_BASIC_SOCKETBUF_HPP__
32 #define __CLAW_BASIC_SOCKETBUF_HPP__
33 
34 #include <streambuf>
35 #include <string>
36 #include <claw/basic_socket.hpp>
37 
38 namespace claw
39 {
40  namespace net
41  {
47  template< typename CharT, typename Traits >
48  class basic_socketbuf : private basic_socket,
49  public std::basic_streambuf<CharT, Traits>
50  {
51  public:
53  typedef CharT char_type;
54 
56  typedef Traits traits_type;
57 
59  typedef typename traits_type::int_type int_type;
60 
62  typedef typename traits_type::pos_type pos_type;
63 
65  typedef typename traits_type::off_type off_type;
66 
69 
70  public:
71  basic_socketbuf( int read_limit = -1 );
72  virtual ~basic_socketbuf();
73 
74  self_type* open( const std::string& addr, int port );
76  self_type* close();
77 
78  bool is_open() const;
79 
80  void set_read_time_limit( int read_limit );
81 
82  protected:
83  virtual int sync();
84  virtual int_type underflow();
85  virtual int_type overflow( int_type c = traits_type::eof() );
86 
87  private:
88  bool connect( const std::string& addr, int port );
89 
90  void create_buffers();
91  void destroy_buffers();
92 
93  bool buffered() const;
94 
95  private:
98  int m_read_limit;
99 
101  char_type* m_input_buffer;
102 
104  size_t m_input_buffer_size;
105 
107  char_type* m_output_buffer;
108 
110  size_t m_output_buffer_size;
111 
113  static const size_t s_buffer_size;
114 
115  }; // class basic_socketbuf
116  } // namespace net
117 } // namespace claw
118 
119 #include <claw/impl/basic_socketbuf.tpp>
120 
121 #endif // __CLAW_BASIC_SOCKETBUF_HPP__
claw::net::basic_socketbuf::traits_type
Traits traits_type
The traits carry some informations about the char_type.
Definition: basic_socketbuf.hpp:56
claw::net::basic_socketbuf::off_type
traits_type::off_type off_type
The type used to represent a delta in the positions.
Definition: basic_socketbuf.hpp:65
claw
This is the main namespace.
Definition: algorithm.hpp:33
claw::net::basic_socketbuf::char_type
CharT char_type
The type of the characters in the stream.
Definition: basic_socketbuf.hpp:53
claw::net::basic_socketbuf::pos_type
traits_type::pos_type pos_type
The type used to represent a position in the stream.
Definition: basic_socketbuf.hpp:62
basic_socket.hpp
Common interface for claw::net::basic_socketbuf and claw::net::socket_server.
claw::net::basic_socketbuf::self_type
basic_socketbuf< char_type, traits_type > self_type
The type of this implementation.
Definition: basic_socketbuf.hpp:68
claw::net::basic_socket::open
basic_socket * open()
Open the socket.
Definition: basic_socket.cpp:48
claw::net::basic_socket
Common interface for claw::net::basic_socketbuf and claw::net::socket_server.
Definition: basic_socket.hpp:46
claw::net::basic_socketbuf
Socket buffer to be used with std::basic_stream, for easy socket reading and writing.
Definition: basic_socketbuf.hpp:48
claw::net::basic_socketbuf::int_type
traits_type::int_type int_type
The type used to represent integers.
Definition: basic_socketbuf.hpp:59
claw::socket_traits_unix::descriptor
int descriptor
Type of the system description of the socket.
Definition: socket_traits_unix.hpp:54