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 osocket_stream.tpp
27 * \brief Implementation of the claw::net::basic_osocket_stream class.
28 * \author Julien Jorge
31 /*----------------------------------------------------------------------------*/
35 template<typename CharT, typename Traits>
36 claw::net::basic_osocket_stream<CharT, Traits>::basic_osocket_stream()
40 } // basic_osocket_stream::basic_osocket_stream()
42 /*----------------------------------------------------------------------------*/
45 * \param address The address to which we will connect.
46 * \param port The port number to use for the connection.
48 template<typename CharT, typename Traits>
49 claw::net::basic_osocket_stream<CharT, Traits>::basic_osocket_stream
50 ( const std::string& address, int port )
54 } // basic_osocket_stream::basic_osocket_stream()
56 /*----------------------------------------------------------------------------*/
60 template<typename CharT, typename Traits>
61 claw::net::basic_osocket_stream<CharT, Traits>::~basic_osocket_stream()
64 } // basic_osocket_stream::~basic_osocket_stream()
66 /*----------------------------------------------------------------------------*/
68 * \brief Get the output buffer.
70 template<typename CharT, typename Traits>
71 typename claw::net::basic_osocket_stream<CharT, Traits>::buffer_type*
72 claw::net::basic_osocket_stream<CharT, Traits>::rdbuf() const
74 return const_cast<buffer_type*>(&m_buffer);
75 } // basic_osocket_stream::rdbuf()
77 /*----------------------------------------------------------------------------*/
79 * \brief Tell if the stream is open.
81 template<typename CharT, typename Traits>
82 bool claw::net::basic_osocket_stream<CharT, Traits>::is_open() const
84 return m_buffer.is_open();
85 } // basic_osocket_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.
93 template<typename CharT, typename Traits>
94 void claw::net::basic_osocket_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_osocket_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.
109 template<typename CharT, typename Traits>
110 void claw::net::basic_osocket_stream<CharT, Traits>::open( int fd )
112 if ( !m_buffer.open(fd) )
113 this->setstate(std::ios_base::failbit);
116 } // basic_osocket_stream::open()
118 /*----------------------------------------------------------------------------*/
120 * \brief Close the connection.
122 template<typename CharT, typename Traits>
123 void claw::net::basic_osocket_stream<CharT, Traits>::close()
125 if ( !m_buffer.close() )
126 this->setstate(std::ios_base::failbit);
127 } // basic_osocket_stream::close()