CppCMS
|
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_REACTOR_H 00009 #define BOOSTER_AIO_REACTOR_H 00010 #include <booster/config.h> 00011 #include <booster/aio/types.h> 00012 #include <memory> 00013 #include <string> 00014 namespace booster { 00015 namespace aio { 00016 00017 class reactor_impl; 00018 00028 class BOOSTER_API reactor : public io_events { 00029 reactor(reactor const &); 00030 void operator=(reactor const &); 00031 public: 00032 00033 static const int use_default = 0; //< Best polling device available on the OS 00034 static const int use_select = 1; //< select() API, default on Windows 00035 static const int use_poll = 2; //< poll() API default on POSIX platforms without better polling support 00036 static const int use_epoll = 3; //< epoll() available and default on Linux 00037 static const int use_dev_poll = 4; //< /dev/poll available and default on Solaris and HP-UX 00038 static const int use_kqueue = 5; //< kqueue available and default on BSD and Mac OS X. 00039 static const int use_max = use_kqueue; //< Maximal number 00040 00042 struct event { 00043 native_type fd; //< A descriptor that event occurred on 00044 int events; //< a bit mask of events \see io_events 00045 }; 00046 00047 00052 reactor(int hint = use_default); 00053 ~reactor(); 00054 00063 void select(native_type fd,int flags); 00072 void select(native_type fd,int flags,system::error_code &e); 00078 void remove(native_type fd) 00079 { 00080 select(fd,0); 00081 } 00087 void remove(native_type fd,system::error_code &e) 00088 { 00089 select(fd,0,e); 00090 } 00091 00100 int poll(event *events,int n,int timeout); 00109 int poll(event *events,int n,int timeout,system::error_code &e); 00110 00114 std::string name() const; 00115 private: 00116 std::auto_ptr<reactor_impl> impl_; 00117 }; 00118 } // aio 00119 } // booster 00120 00121 00122 #endif