basic_socketbuf.hpp
Go to the documentation of this file.
/*
CLAW - a C++ Library Absolutely Wonderful
CLAW is a free library without any particular aim but being useful to
anyone.
Copyright (C) 2005-2011 Julien Jorge
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
contact: julien.jorge@gamned.org
*/
#ifndef __CLAW_BASIC_SOCKETBUF_HPP__
#define __CLAW_BASIC_SOCKETBUF_HPP__
#include <streambuf>
#include <string>
#include <claw/basic_socket.hpp>
namespace claw
{
namespace net
{
template< typename CharT, typename Traits >
class basic_socketbuf : private basic_socket,
public std::basic_streambuf<CharT, Traits>
{
public:
typedef CharT char_type;
typedef Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
typedef basic_socketbuf<char_type, traits_type> self_type;
public:
basic_socketbuf( int read_limit = -1 );
virtual ~basic_socketbuf();
self_type* open( const std::string& addr, int port );
self_type* open( socket_traits::descriptor d );
self_type* close();
bool is_open() const;
void set_read_time_limit( int read_limit );
protected:
virtual int sync();
virtual int_type underflow();
virtual int_type overflow( int_type c = traits_type::eof() );
private:
bool connect( const std::string& addr, int port );
void create_buffers();
void destroy_buffers();
bool buffered() const;
private:
int m_read_limit;
char_type* m_input_buffer;
size_t m_input_buffer_size;
char_type* m_output_buffer;
size_t m_output_buffer_size;
static const size_t s_buffer_size;
}; // class basic_socketbuf
} // namespace net
} // namespace claw
#include <claw/impl/basic_socketbuf.tpp>
#endif // __CLAW_BASIC_SOCKETBUF_HPP__
basic_socket.hpp
Common interface for claw::net::basic_socketbuf and claw::net::socket_server.
claw::net::basic_socket::basic_socket
basic_socket()
Constructor.
Definition basic_socket.cpp:37
claw::net::basic_socket::open
basic_socket * open()
Open the socket.
Definition basic_socket.cpp:48
claw::net::basic_socket::close
basic_socket * close()
Close the socket.
Definition basic_socket.cpp:65
claw::net::basic_socket::is_open
bool is_open() const
Tell if the socket is open.
Definition basic_socket.cpp:84
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::char_type
CharT char_type
The type of the characters in the stream.
Definition basic_socketbuf.hpp:53
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::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_socketbuf::int_type
traits_type::int_type int_type
The type used to represent integers.
Definition basic_socketbuf.hpp:59
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
claw::socket_traits_unix::descriptor
int descriptor
Type of the system description of the socket.
Definition socket_traits_unix.hpp:54
claw::net
Network communications.
Definition basic_socket.hpp:40
claw
This is the main namespace.
Definition algorithm.hpp:34