blob: 51d9bef6661b223cb387d265e66a6864c244cc0c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "wakeup_pipe.h"
#include <poll.h>
#include <map>
#include <mutex>
#define EPOLLERR POLLERR
#define EPOLLHUP POLLHUP
#define EPOLLIN POLLIN
#define EPOLLOUT POLLOUT
namespace vespalib {
// structure describing which event occurred.
struct epoll_event
{
struct {
void *ptr;
} data;
uint32_t events;
};
/**
* The Epoll class is a thin wrapper around basic emulation of the epoll
* related system calls.
**/
class Epoll
{
private:
std::mutex _monitored_lock;
WakeupPipe _wakeup;
std::map<int, epoll_event> _monitored;
public:
Epoll();
~Epoll();
void add(int fd, void *ctx, bool read, bool write);
void update(int fd, void *ctx, bool read, bool write);
void remove(int fd);
size_t wait(epoll_event *events, size_t max_events, int timeout_ms);
};
}
|