Claw  1.7.3
osocket_stream.tpp
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 /*----------------------------------------------------------------------------*/
35 template<typename CharT, typename Traits>
37  : super(&m_buffer)
38 {
39 
40 } // basic_osocket_stream::basic_osocket_stream()
41 
42 /*----------------------------------------------------------------------------*/
48 template<typename CharT, typename Traits>
50 ( const std::string& address, int port )
51  : super(&m_buffer)
52 {
53  open(address, port);
54 } // basic_osocket_stream::basic_osocket_stream()
55 
56 /*----------------------------------------------------------------------------*/
60 template<typename CharT, typename Traits>
62 {
63  // nothing to do
64 } // basic_osocket_stream::~basic_osocket_stream()
65 
66 /*----------------------------------------------------------------------------*/
70 template<typename CharT, typename Traits>
73 {
74  return const_cast<buffer_type*>(&m_buffer);
75 } // basic_osocket_stream::rdbuf()
76 
77 /*----------------------------------------------------------------------------*/
81 template<typename CharT, typename Traits>
83 {
84  return m_buffer.is_open();
85 } // basic_osocket_stream::()
86 
87 /*----------------------------------------------------------------------------*/
93 template<typename CharT, typename Traits>
95 ( const std::string& address, int port )
96 {
97  if ( !m_buffer.open(address, port) )
98  this->setstate(std::ios_base::failbit);
99  else
100  this->clear();
101 } // basic_osocket_stream::open()
102 
103 /*----------------------------------------------------------------------------*/
109 template<typename CharT, typename Traits>
111 {
112  if ( !m_buffer.open(fd) )
113  this->setstate(std::ios_base::failbit);
114  else
115  this->clear();
116 } // basic_osocket_stream::open()
117 
118 /*----------------------------------------------------------------------------*/
122 template<typename CharT, typename Traits>
124 {
125  if ( !m_buffer.close() )
126  this->setstate(std::ios_base::failbit);
127 } // basic_osocket_stream::close()
128