MACE  1.0.0
 All Classes Namespaces Files Functions Variables Enumerations Defines
libs/cmt/include/mace/cmt/asio/tcp/socket.hpp
00001 #ifndef _MACE_CMT_ASIO_TCP_SOCKET_HPP
00002 #define _MACE_CMT_ASIO_TCP_SOCKET_HPP
00003 #include <boost/asio.hpp>
00004 #include <mace/cmt/future.hpp>
00005 
00006 namespace mace { namespace cmt { namespace asio { namespace tcp {
00007   namespace detail { struct socket; }
00008 
00015   class socket  : public boost::asio::ip::tcp::socket {
00016     public:
00017       typedef boost::shared_ptr<socket> ptr;
00018 
00019       socket();
00020       ~socket();
00021 
00022       mace::cmt::future<boost::system::error_code> connect( const boost::asio::ip::tcp::endpoint& ep );
00023 
00027       struct iterator : public std::iterator<std::input_iterator_tag,char,void> {
00028         iterator( mace::cmt::asio::tcp::socket* _s = NULL)
00029         :s(_s){ if(_s){++*this;}  }
00030 
00031         inline const char& operator*()const  { return value;  }
00032         inline const char* operator->()const { return &value; }
00033         inline char& operator*() { return value;  }
00034         inline char* operator->(){ return &value; }
00035 
00036         iterator& operator++();
00037         iterator operator++(int);
00038 
00039         bool operator == ( const iterator& i )const { return s == i.s; }
00040         bool operator != ( const iterator& i )const { return s != i.s; }
00041 
00042         private:
00043           char               value;
00044           mace::cmt::asio::tcp::socket* s;
00045       };
00046 
00047       size_t read_some( char* buffer, size_t size );
00048       size_t read( char* buffer, size_t size );
00049       size_t write( const char* buffer, size_t size );
00050 
00051       void flush();
00052     private:
00053       detail::socket* my;
00054   };
00055 
00056 } } } } // namespace mace::cmt::asio::tcp
00057 
00058 #endif