00001 #ifndef _sys_Poller_h
00002 #define _sys_Poller_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "Time.h"
00026 #include "Socket.h"
00027
00028 #include <stdint.h>
00029
00030 #include <boost/shared_ptr.hpp>
00031
00032 namespace qpid {
00033 namespace sys {
00034
00038 class Poller;
00039 class PollerHandlePrivate;
00040 class PollerHandle {
00041 friend class Poller;
00042
00043 PollerHandlePrivate* const impl;
00044 const Socket& socket;
00045
00046 public:
00047 PollerHandle(const Socket& s);
00048
00049
00050
00051 void deferDelete();
00052
00053
00054 virtual ~PollerHandle();
00055
00056 const Socket& getSocket() const {return socket;}
00057 };
00058
00063 class PollerPrivate;
00064 class Poller {
00065 PollerPrivate* const impl;
00066
00067 public:
00068 typedef boost::shared_ptr<Poller> shared_ptr;
00069
00070 enum Direction {
00071 NONE = 0,
00072 IN,
00073 OUT,
00074 INOUT
00075 };
00076
00077 enum EventType {
00078 INVALID = 0,
00079 READABLE,
00080 WRITABLE,
00081 READ_WRITABLE,
00082 DISCONNECTED,
00083 SHUTDOWN,
00084 TIMEOUT
00085 };
00086
00087 struct Event {
00088 PollerHandle* handle;
00089 EventType type;
00090
00091 Event(PollerHandle* handle0, EventType type0) :
00092 handle(handle0),
00093 type(type0) {
00094 }
00095 };
00096
00097 Poller();
00098 ~Poller();
00100 void shutdown();
00101
00102 void addFd(PollerHandle& handle, Direction dir);
00103 void delFd(PollerHandle& handle);
00104 void modFd(PollerHandle& handle, Direction dir);
00105 void rearmFd(PollerHandle& handle);
00106 Event wait(Duration timeout = TIME_INFINITE);
00107 };
00108
00109 }}
00110 #endif // _sys_Poller_h