2 CLAW - a C++ Library Absolutely Wonderful
4 CLAW is a free library without any particular aim but being useful to
7 Copyright (C) 2005-2011 Julien Jorge
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.
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.
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
23 contact: julien.jorge@gamned.org
26 * \file isocket_stream.tpp
27 * \brief Implementation of the claw::net::basic_isocket_stream class.
28 * \author Julien Jorge
31/*----------------------------------------------------------------------------*/
35template<typename CharT, typename Traits>
36claw::net::basic_isocket_stream<CharT, Traits>::basic_isocket_stream()
40} // basic_isocket_stream::basic_isocket_stream()
42/*----------------------------------------------------------------------------*/
45 * \param address The address to which we will connect.
46 * \param port The port number to use for the connection.
48template<typename CharT, typename Traits>
49claw::net::basic_isocket_stream<CharT, Traits>::basic_isocket_stream
50( const std::string& address, int port )
54} // basic_isocket_stream::basic_isocket_stream()
56/*----------------------------------------------------------------------------*/
60template<typename CharT, typename Traits>
61claw::net::basic_isocket_stream<CharT, Traits>::~basic_isocket_stream()
64} // basic_isocket_stream::~basic_isocket_stream()
66/*----------------------------------------------------------------------------*/
68 * \brief Get the input buffer.
70template<typename CharT, typename Traits>
71typename claw::net::basic_isocket_stream<CharT, Traits>::buffer_type*
72claw::net::basic_isocket_stream<CharT, Traits>::rdbuf() const
74 return const_cast<buffer_type*>(&m_buffer);
75} // basic_isocket_stream::rdbuf()
77/*----------------------------------------------------------------------------*/
79 * \brief Tell if the stream is open.
81template<typename CharT, typename Traits>
82bool claw::net::basic_isocket_stream<CharT, Traits>::is_open() const
84 return m_buffer.is_open();
85} // basic_isocket_stream::()
87/*----------------------------------------------------------------------------*/
89 * \brief Connect the socket to an address.
90 * \param address The address to which we will connect.
91 * \param port The port number to use for the connection.
93template<typename CharT, typename Traits>
94void claw::net::basic_isocket_stream<CharT, Traits>::open
95( const std::string& address, int port )
97 if ( !m_buffer.open(address, port) )
98 this->setstate(std::ios_base::failbit);
101} // basic_isocket_stream::open()
103/*----------------------------------------------------------------------------*/
105 * \brief Link the socket to a file descriptor.
106 * \param fd The file descriptor.
107 * \remark This method should be only called by claw::net::socket_server.
109template<typename CharT, typename Traits>
110void claw::net::basic_isocket_stream<CharT, Traits>::open( int fd )
112 if ( !m_buffer.open(fd) )
113 this->setstate(std::ios_base::failbit);
116} // basic_isocket_stream::open()
118/*----------------------------------------------------------------------------*/
120 * \brief Close the connection.
122template<typename CharT, typename Traits>
123void claw::net::basic_isocket_stream<CharT, Traits>::close()
125 if ( !m_buffer.close() )
126 this->setstate(std::ios_base::failbit);
127} // basic_isocket_stream::close()