/* */ #ifndef _D_KQUEUE_EVENT_POLL_H_ #define _D_KQUEUE_EVENT_POLL_H_ #include "EventPoll.h" #include #include #include #include #include "Event.h" #ifdef ENABLE_ASYNC_DNS # include "AsyncNameResolver.h" #endif // ENABLE_ASYNC_DNS namespace aria2 { class Logger; class KqueueEventPoll : public EventPoll { private: class KSocketEntry; typedef Event KEvent; typedef CommandEvent KCommandEvent; typedef ADNSEvent KADNSEvent; typedef AsyncNameResolverEntry KAsyncNameResolverEntry; friend class AsyncNameResolverEntry; class KSocketEntry: public SocketEntry { public: KSocketEntry(sock_t socket); // eventlist should be at least size 2. This function returns the // number of filled struct kevent in eventlist. size_t getEvents(struct kevent* eventlist); }; friend int accumulateEvent(int events, const KEvent& event); private: std::deque > _socketEntries; #ifdef ENABLE_ASYNC_DNS std::deque > _nameResolverEntries; #endif // ENABLE_ASYNC_DNS int _kqfd; size_t _kqEventsSize; struct kevent* _kqEvents; static const size_t KQUEUE_EVENTS_MAX = 1024; Logger* _logger; bool addEvents(sock_t socket, const KEvent& event); bool deleteEvents(sock_t socket, const KEvent& event); bool addEvents(sock_t socket, Command* command, int events, const SharedHandle& rs); bool deleteEvents(sock_t socket, Command* command, const SharedHandle& rs); public: KqueueEventPoll(); bool good() const; virtual ~KqueueEventPoll(); virtual void poll(const struct timeval& tv); virtual bool addEvents(sock_t socket, Command* command, EventPoll::EventType events); virtual bool deleteEvents(sock_t socket, Command* command, EventPoll::EventType events); #ifdef ENABLE_ASYNC_DNS virtual bool addNameResolver(const SharedHandle& resolver, Command* command); virtual bool deleteNameResolver (const SharedHandle& resolver, Command* command); #endif // ENABLE_ASYNC_DNS static const int IEV_READ = POLLIN; static const int IEV_WRITE = POLLOUT; static const int IEV_ERROR = POLLERR; static const int IEV_HUP = POLLHUP; }; } // namespace aria2 #endif // _D_KQUEUE_EVENT_POLL_H_