00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00025 #ifndef SOCKETSTREAM_BASIC_OSOCKETSTREAM_H
00026 #define SOCKETSTREAM_BASIC_OSOCKETSTREAM_H 1
00027 
00028 #include <socketstream/config.h>
00029 
00030 #include <ostream>
00031 #include <socketstream/basic_socketbuf.h>
00032 
00033 namespace ss {
00034 
00038   template <typename _CharT, typename _Traits>
00039   class basic_osocketstream
00040   : public std::basic_ostream<_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_ostream<char_type, traits_type> __stream_type;
00063 
00067     basic_osocketstream()
00068     : __stream_type(&_M_buffer), _M_buffer()
00069     { }
00070 
00077     basic_osocketstream(family __f, style __s)
00078     : __stream_type(&_M_buffer), _M_buffer(__f, __s)
00079     { }
00080 
00086     virtual ~basic_osocketstream()
00087     { }
00088 
00094     bool
00095     is_open ()
00096     { return _M_buffer.is_open(); }
00097 
00103     template <typename AddressT>
00104     void
00105     connect (AddressT& __addr)
00106     {
00107       if (!_M_buffer.connect(__addr))
00108         this->setstate(std::ios_base::failbit);
00109     }
00110 
00120     void
00121     shutdown (shutmode __mode = sockets_base::rw)
00122     {
00123       if (!_M_buffer.shutdown(__mode))
00124         this->setstate(std::ios_base::failbit);
00125     }
00126 
00130     __streambuf_type*
00131     rdbuf () const
00132     { return const_cast<__streambuf_type*>(&_M_buffer); }
00133 
00134     __stream_type&
00135     operator>> (flag& __flag)
00136     {
00137       _M_buffer.setf(__flag);
00138       return *this;
00139     }
00140 
00141   private:
00142 
00143     __streambuf_type _M_buffer;
00144 
00145   };
00146 
00147   typedef basic_osocketstream<char, std::char_traits<char> > osocketstream;
00148 
00149 }
00150 
00151 #endif  // SOCKETSTREAM_BASIC_OSOCKETSTREAM_H