-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfde.h
59 lines (49 loc) · 1.17 KB
/
fde.h
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
Copyright (c) 2012-2014 The SSDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
*/
#ifndef UTIL_FDE_H
#define UTIL_FDE_H
#include <vector>
#include <sys/epoll.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#define FDEVENT_NONE (0)
#define FDEVENT_IN (1 << 0)
#define FDEVENT_PRI (1 << 1)
#define FDEVENT_OUT (1 << 2)
#define FDEVENT_HUP (1 << 3)
#define FDEVENT_ERR (1 << 4)
struct Fdevent {
int fd;
int s_flags; // subscribed events
int events; // ready events
struct {
int num;
void* ptr;
} data;
};
class Fdevents {
public:
typedef std::vector<struct Fdevent*> events_t;
private:
static const int MAX_FDS = 8 * 1024;
int ep_fd;
struct epoll_event ep_events[MAX_FDS];
events_t events;
events_t ready_events;
struct Fdevent* get_fde(int fd);
public:
Fdevents();
~Fdevents();
bool isset(int fd, int flag);
int set(int fd, int flags, int data_num, void* data_ptr);
int del(int fd);
int clr(int fd, int flags);
const events_t* wait(int timeout_ms = -1);
};
#endif