Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

basic_iosocketstream.h

Go to the documentation of this file.
00001 // -*- Socket Streams -*-
00002 
00003 // Copyright (C) 2003, 2004, 2005 Pedro LamarĂ£o <pedro.lamarao@mndfck.org>
00004 
00005 // This file is part of the Socket Streams Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU Lesser General Public License as published by the
00008 // Free Software Foundation; either version 2.1 of the License
00009 // or (at your option) any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU Lesser General Public License for more details.
00015 
00016 // You should have received a copy of the GNU Lesser General Public License along
00017 // with this library; see the file COPYING. If not, write to the Free
00018 // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
00019 // USA
00020 
00025 #ifndef SOCKETSTREAM_BASIC_IOSOCKETSTREAM_H
00026 #define SOCKETSTREAM_BASIC_IOSOCKETSTREAM_H 1
00027 
00028 #include <socketstream/config.h>
00029 
00030 #include <iostream>
00031 #include <socketstream/basic_socketbuf.h>
00032 
00033 namespace ss {
00034 
00038   template <typename _CharT, typename _Traits>
00039   class basic_socketstream
00040   : public std::basic_iostream<_CharT, _Traits>,
00041     public sockets_base
00042   {
00043   public:
00044 
00046 
00053     typedef _CharT     char_type;
00054     typedef _Traits  traits_type;
00055 
00056     typedef typename traits_type::int_type int_type;
00057     typedef typename traits_type::pos_type pos_type;
00058     typedef typename traits_type::off_type off_type;
00060 
00061     typedef basic_socketbuf<char_type, traits_type>   __streambuf_type;
00062     typedef std::basic_iostream<char_type, traits_type>  __stream_type;
00063     
00064     template <typename C, typename T>
00065     friend class basic_listener;
00066 
00070     basic_socketstream()
00071     : __stream_type(&_M_buffer), _M_buffer()
00072     { }
00073 
00080     basic_socketstream(family __f, style __s)
00081     : __stream_type(&_M_buffer), _M_buffer(__f, __s)
00082     { }
00083 
00089     virtual ~basic_socketstream()
00090     { }
00091 
00097     bool
00098     is_open ()
00099     { return _M_buffer.is_open(); }
00100 
00106         template <typename AddressT>
00107     void
00108     connect (AddressT& __addr)
00109     {
00110       if (!_M_buffer.connect(__addr))
00111         this->setstate(std::ios_base::failbit);
00112     }
00113 
00123     void
00124     shutdown (shutmode __mode = sockets_base::rw)
00125     {
00126       if (!_M_buffer.shutdown(__mode))
00127         this->setstate(std::ios_base::failbit);
00128     }
00129 
00133     __streambuf_type*
00134     rdbuf () const
00135     { return const_cast<__streambuf_type*>(&_M_buffer); }
00136 
00137     __stream_type&
00138     operator>> (flag& __flag)
00139     {
00140       _M_buffer.setf(__flag);
00141       return *this;
00142     }
00143 
00144     __stream_type&
00145     operator<< (flag& __flag)
00146     {
00147       _M_buffer.setf(__flag);
00148       return *this;
00149     }
00150 
00151   protected:
00152 
00158     basic_socketstream(basic_socket::descriptor_t descriptor)
00159     : __stream_type(&_M_buffer), _M_buffer(descriptor)
00160     { }
00161 
00162     __streambuf_type _M_buffer;
00163 
00164   };
00165 
00166   typedef basic_socketstream<char, std::char_traits<char> > socketstream;
00167 
00168 }
00169 
00170 #endif  // SOCKETSTREAM_BASIC_IOSOCKETSTREAM_H

Generated on Sat May 21 21:25:32 2005 for Socket Streams Library by  doxygen 1.4.3