Claw
1.7.0
|
00001 /* 00002 CLAW - a C++ Library Absolutely Wonderful 00003 00004 CLAW is a free library without any particular aim but being useful to 00005 anyone. 00006 00007 Copyright (C) 2005-2011 Julien Jorge 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 00023 contact: julien.jorge@gamned.org 00024 */ 00031 /*----------------------------------------------------------------------------*/ 00037 template<typename CharT, typename Traits> 00038 claw::net::basic_socket_stream<CharT, Traits>::basic_socket_stream 00039 ( int read_delay ) 00040 : m_buffer(read_delay) 00041 { 00042 init(&m_buffer); 00043 } // basic_socket_stream::basic_socket_stream() 00044 00045 /*----------------------------------------------------------------------------*/ 00053 template<typename CharT, typename Traits> 00054 claw::net::basic_socket_stream<CharT, Traits>::basic_socket_stream 00055 ( const char* address, int port, int read_delay ) 00056 : m_buffer(read_delay) 00057 { 00058 init(&m_buffer); 00059 open(address, port); 00060 } // basic_socket_stream::basic_socket_stream() 00061 00062 /*----------------------------------------------------------------------------*/ 00066 template<typename CharT, typename Traits> 00067 claw::net::basic_socket_stream<CharT, Traits>::~basic_socket_stream() 00068 { 00069 // nothing to do 00070 } // basic_socket_stream::~basic_socket_stream() 00071 00072 /*----------------------------------------------------------------------------*/ 00076 template<typename CharT, typename Traits> 00077 typename claw::net::basic_socket_stream<CharT, Traits>::buffer_type* 00078 claw::net::basic_socket_stream<CharT, Traits>::rdbuf() const 00079 { 00080 return const_cast<buffer_type*>(&m_buffer); 00081 } // basic_socket_stream::rdbuf() 00082 00083 /*----------------------------------------------------------------------------*/ 00087 template<typename CharT, typename Traits> 00088 bool claw::net::basic_socket_stream<CharT, Traits>::is_open() const 00089 { 00090 return m_buffer.is_open(); 00091 } // basic_socket_stream::is_open() 00092 00093 /*----------------------------------------------------------------------------*/ 00099 template<typename CharT, typename Traits> 00100 void claw::net::basic_socket_stream<CharT, Traits>::set_read_time_limit 00101 ( int read_limit ) 00102 { 00103 m_buffer.set_read_time_limit(read_limit); 00104 } // // basic_socket_stream::set_read_time_limit() 00105 00106 /*----------------------------------------------------------------------------*/ 00112 template<typename CharT, typename Traits> 00113 void claw::net::basic_socket_stream<CharT, Traits>::open 00114 ( const char* address, int port ) 00115 { 00116 if ( !m_buffer.open(address, port) ) 00117 this->setstate(std::ios_base::failbit); 00118 else 00119 this->clear(); 00120 } // basic_socket_stream::open() 00121 00122 /*----------------------------------------------------------------------------*/ 00128 template<typename CharT, typename Traits> 00129 void claw::net::basic_socket_stream<CharT, Traits>::open( int fd ) 00130 { 00131 if ( !m_buffer.open(fd) ) 00132 this->setstate(std::ios_base::failbit); 00133 else 00134 this->clear(); 00135 } // basic_socket_stream::open() 00136 00137 /*----------------------------------------------------------------------------*/ 00141 template<typename CharT, typename Traits> 00142 void claw::net::basic_socket_stream<CharT, Traits>::close() 00143 { 00144 if ( !m_buffer.close() ) 00145 this->setstate(std::ios_base::failbit); 00146 } // basic_socket_stream::close() 00147