Claw  1.7.3
socket_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 /*----------------------------------------------------------------------------*/
37 template<typename CharT, typename Traits>
39 ( int read_delay )
40  : m_buffer(read_delay)
41 {
42  this->init(&m_buffer);
43 } // basic_socket_stream::basic_socket_stream()
44 
45 /*----------------------------------------------------------------------------*/
53 template<typename CharT, typename Traits>
55 ( const char* address, int port, int read_delay )
56  : m_buffer(read_delay)
57 {
58  this->init(&m_buffer);
59  open(address, port);
60 } // basic_socket_stream::basic_socket_stream()
61 
62 /*----------------------------------------------------------------------------*/
66 template<typename CharT, typename Traits>
68 {
69  // nothing to do
70 } // basic_socket_stream::~basic_socket_stream()
71 
72 /*----------------------------------------------------------------------------*/
76 template<typename CharT, typename Traits>
79 {
80  return const_cast<buffer_type*>(&m_buffer);
81 } // basic_socket_stream::rdbuf()
82 
83 /*----------------------------------------------------------------------------*/
87 template<typename CharT, typename Traits>
89 {
90  return m_buffer.is_open();
91 } // basic_socket_stream::is_open()
92 
93 /*----------------------------------------------------------------------------*/
99 template<typename CharT, typename Traits>
101 ( int read_limit )
102 {
103  m_buffer.set_read_time_limit(read_limit);
104 } // // basic_socket_stream::set_read_time_limit()
105 
106 /*----------------------------------------------------------------------------*/
112 template<typename CharT, typename Traits>
114 ( const char* address, int port )
115 {
116  if ( !m_buffer.open(address, port) )
117  this->setstate(std::ios_base::failbit);
118  else
119  this->clear();
120 } // basic_socket_stream::open()
121 
122 /*----------------------------------------------------------------------------*/
128 template<typename CharT, typename Traits>
130 {
131  if ( !m_buffer.open(fd) )
132  this->setstate(std::ios_base::failbit);
133  else
134  this->clear();
135 } // basic_socket_stream::open()
136 
137 /*----------------------------------------------------------------------------*/
141 template<typename CharT, typename Traits>
143 {
144  if ( !m_buffer.close() )
145  this->setstate(std::ios_base::failbit);
146 } // basic_socket_stream::close()
147