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
38namespace claw
39{
40 namespace net
41 {
47 template< typename CharT, typename Traits >
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__
Common interface for claw::net::basic_socketbuf and claw::net::socket_server.
Common interface for claw::net::basic_socketbuf and claw::net::socket_server.
basic_socket * open()
Open the socket.
Socket buffer to be used with std::basic_stream, for easy socket reading and writing.
basic_socketbuf< char_type, traits_type > self_type
The type of this implementation.
traits_type::int_type int_type
The type used to represent integers.
traits_type::pos_type pos_type
The type used to represent a position in the stream.
traits_type::off_type off_type
The type used to represent a delta in the positions.
Traits traits_type
The traits carry some informations about the char_type.
CharT char_type
The type of the characters in the stream.
int descriptor
Type of the system description of the socket.
This is the main namespace.
Definition algorithm.hpp:34