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
| | // SPDX-License-Identifier: GPL-2.0-or-later
/* epoll_ctl.c - epoll manipulation helpers
*
* Copyright Red Hat
* Author: Laurent Vivier <lvivier@redhat.com>
*/
#include <errno.h>
#include "epoll_ctl.h"
/**
* epoll_add() - Add a file descriptor to an epollfd
* @epollfd: epoll file descriptor to add to
* @events: epoll events
* @ref: epoll reference for the file descriptor (includes fd and metadata)
*
* Return: 0 on success, negative errno on failure
*/
int epoll_add(int epollfd, uint32_t events, union epoll_ref *ref)
{
struct epoll_event ev;
int ret;
ev.events = events;
ev.data.u64 = ref->u64;
ret = epoll_ctl(epollfd, EPOLL_CTL_ADD, ref->fd, &ev);
if (ret == -1) {
ret = -errno;
warn("Failed to add fd to epoll: %s", strerror_(-ret));
}
return ret;
}
/**
* epoll_del() - Remove a file descriptor from an epollfd
* @epollfd: epoll file descriptor to remove from
* @fd: File descriptor to remove
*/
void epoll_del(int epollfd, int fd)
{
epoll_ctl(epollfd, EPOLL_CTL_DEL, fd, NULL);
}
|