CppCMS
booster/aio/stream_socket.h
00001 //
00002 //  Copyright (C) 2009-2012 Artyom Beilis (Tonkikh)
00003 //
00004 //  Distributed under the Boost Software License, Version 1.0. (See
00005 //  accompanying file LICENSE_1_0.txt or copy at
00006 //  http://www.boost.org/LICENSE_1_0.txt)
00007 //
00008 #ifndef BOOSTER_AIO_STREAM_SOCKET_H
00009 #define BOOSTER_AIO_STREAM_SOCKET_H
00010 
00011 #include <booster/aio/types.h>
00012 #include <booster/callback.h>
00013 #include <booster/hold_ptr.h>
00014 #include <booster/noncopyable.h>
00015 #include <booster/aio/endpoint.h>
00016 #include <booster/aio/basic_io_device.h>
00017 #include <booster/aio/basic_socket.h>
00018 
00019 namespace booster {
00020 namespace aio {
00021         class mutable_buffer;
00022         class const_buffer;
00023         class io_service;
00024         
00025         
00026         
00031         class BOOSTER_API stream_socket : public basic_socket {
00032         public:
00036                 typedef enum {
00037                         shut_rd, //< Shutdown read operations 
00038                         shut_wr, //< Shutdown write operations
00039                         shut_rdwr //< Shutdown both read and write operations
00040                 } how_type;
00041 
00045                 stream_socket();
00049                 stream_socket(io_service &srv);
00050                 ~stream_socket();
00051 
00057                 void open(family_type d);
00063                 void open(family_type d,system::error_code &e);
00064 
00070                 void shutdown(how_type h);
00076                 void shutdown(how_type h,system::error_code &e);
00077 
00083                 void connect(endpoint const &ep);
00089                 void connect(endpoint const &ep,system::error_code &e);
00096                 void async_connect(endpoint const &ep,event_handler const &h);
00097 
00103                 size_t read_some(mutable_buffer const &buffer);
00109                 size_t read_some(mutable_buffer const &buffer,system::error_code &e);
00110                 
00116                 size_t write_some(const_buffer const &buffer);
00122                 size_t write_some(const_buffer const &buffer,system::error_code &e);
00123 
00130                 size_t read(mutable_buffer const &buffer);
00137                 size_t write(const_buffer const &buffer);
00138                 
00145                 size_t read(mutable_buffer const &buffer,system::error_code &e);
00152                 size_t write(const_buffer const &buffer,system::error_code &e);
00153 
00163                 void async_read_some(mutable_buffer const &buffer,io_handler const &h);
00173                 void async_write_some(const_buffer const &buffer,io_handler const &h);
00174 
00184                 void async_read(mutable_buffer const &buffer,io_handler const &h);
00194                 void async_write(const_buffer const &buffer,io_handler const &h);
00195 
00196         private:
00197                 int readv(mutable_buffer const &b);
00198                 int writev(const_buffer const &b);
00199 
00200                 struct data;
00201                 hold_ptr<data> d;
00202         };
00203 
00208         BOOSTER_API void socket_pair(stream_socket &s1,stream_socket &s2,system::error_code &e);
00213         BOOSTER_API void socket_pair(stream_socket &s1,stream_socket &s2);
00214         
00215 
00216 } // aio
00217 } // booster
00218 
00219 #endif