cmogstored.git  about / heads / tags
alternative mogstored implementation for MogileFS
blob d8cbdb9c006c292b2cc970544a9e9f119851e5e3 1201 bytes (raw)
$ git show HEAD:compat_epoll_pwait.h	# shows this blob on the CLI

 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
 
/*
 * fake epoll_pwait() implemented using ppoll + epoll_wait.
 * This is only for Linux 2.6.18 / glibc 2.5 systems (Enterprise distros :P)
 *
 * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
 * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 */

#if !defined(HAVE_EPOLL_PWAIT) \
    && defined(HAVE_PPOLL) && defined(HAVE_EPOLL_WAIT)
static int my_epoll_pwait(int epfd, struct epoll_event *events,
                          int maxevents, int timeout, const sigset_t *sigmask)
{
	struct pollfd pfds = { .fd = epfd, .events = POLLIN };
	int rc;
	struct timespec ts;
	struct timespec *tsp;

	if (timeout < 0) {
		tsp = NULL;
	} else {
		ts.tv_sec = timeout / 1000;
		ts.tv_nsec = (timeout % 1000) * 1000000;
		tsp = &ts;
	}

	/* wait on just the epoll descriptor itself */
	rc = ppoll(&pfds, 1, tsp, sigmask);
	if (rc < 0)
		assert((errno == EINTR || errno == ENOMEM)
		       && "ppoll usage bug");

	/* no sleep for the actual epoll call */
	return rc > 0 ? epoll_wait(epfd, events, maxevents, 0) : 0;
}
#define epoll_pwait(epfd,events,maxevents,timeout,sigmask) \
        my_epoll_pwait((epfd),(events),(maxevents),(timeout),(sigmask))
#endif /* epoll_pwait */

git clone https://yhbt.net/cmogstored.git