CppCMS
booster/aio/basic_io_device.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_BASIC_IO_DEVICE_H
00009 #define BOOSTER_AIO_BASIC_IO_DEVICE_H
00010 
00011 #include <booster/aio/types.h>
00012 #include <booster/hold_ptr.h>
00013 #include <booster/callback.h>
00014 #include <booster/noncopyable.h>
00015 
00016 namespace booster {
00017 namespace aio {
00018         class io_service;
00019         class endpoint;
00020 
00036         class BOOSTER_API basic_io_device : public noncopyable {
00037         public:
00041                 basic_io_device();
00045                 basic_io_device(io_service &srv);
00049                 virtual ~basic_io_device();
00050 
00054                 bool has_io_service();
00058                 io_service &get_io_service();
00062                 void set_io_service(io_service &srv);
00066                 void reset_io_service();
00067 
00073                 void attach(native_type fd);
00077                 void assign(native_type fd);
00083                 native_type release();
00087                 native_type native();
00088         
00094                 void close();
00100                 void close(system::error_code &e);
00101 
00107                 void on_readable(event_handler const &r);
00113                 void on_writeable(event_handler const &r);
00117                 void cancel();
00118 
00122                 basic_io_device &lowest_layer();
00123 
00129                 void set_non_blocking(bool nonblocking);
00135                 void set_non_blocking(bool nonblocking,system::error_code &e);
00136 
00140                 static bool would_block(system::error_code const &e);
00141 
00142         protected:
00146                 bool dont_block(event_handler const &c);
00150                 bool dont_block(io_handler const &c);
00151         private:
00152                 
00153                 struct data;
00154                 hold_ptr<data> d;
00155                 native_type fd_;
00156                 bool owner_;
00157                 bool nonblocking_was_set_;
00158                 io_service *srv_;
00159         };
00160 
00161 
00162 
00163 } // aio
00164 } // booster
00165 
00166 #endif