mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-02-20 15:14:26 +01:00
53 lines
1.2 KiB
C++
53 lines
1.2 KiB
C++
/**
|
|
*
|
|
* KQueue.h
|
|
* An Tao
|
|
*
|
|
* Copyright 2018, An Tao. All rights reserved.
|
|
* https://github.com/an-tao/trantor
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the License file.
|
|
*
|
|
* Trantor
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
#include "core/loops/event_loop.h"
|
|
#include "core/loops/poller.h"
|
|
|
|
#if (defined(__unix__) && !defined(__linux__)) || \
|
|
(defined(__APPLE__) && defined(__MACH__))
|
|
#define USE_KQUEUE
|
|
#include <memory>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
using EventList = std::vector<struct kevent>;
|
|
#endif
|
|
|
|
namespace trantor {
|
|
class Channel;
|
|
|
|
class KQueue : public Poller {
|
|
public:
|
|
explicit KQueue(EventLoop *loop);
|
|
virtual ~KQueue();
|
|
virtual void poll(int timeoutMs, ChannelList *activeChannels) override;
|
|
virtual void updateChannel(Channel *channel) override;
|
|
virtual void removeChannel(Channel *channel) override;
|
|
virtual void resetAfterFork() override;
|
|
|
|
private:
|
|
#ifdef USE_KQUEUE
|
|
static const int kInitEventListSize = 16;
|
|
int kqfd_;
|
|
EventList events_;
|
|
using ChannelMap = std::unordered_map<int, std::pair<int, Channel *> >;
|
|
ChannelMap channels_;
|
|
|
|
void fillActiveChannels(int numEvents, ChannelList *activeChannels) const;
|
|
void update(Channel *channel);
|
|
#endif
|
|
};
|
|
|
|
} // namespace trantor
|