mirror of
https://github.com/fluencelabs/redis
synced 2025-03-30 22:31:03 +00:00
implement aeWait using poll(2). Fixes issue #267.
This commit is contained in:
parent
70381bbf82
commit
3e1e1ac27d
21
src/ae.c
21
src/ae.c
@ -35,6 +35,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <poll.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "ae.h"
|
#include "ae.h"
|
||||||
@ -369,21 +370,17 @@ int aeProcessEvents(aeEventLoop *eventLoop, int flags)
|
|||||||
/* Wait for millseconds until the given file descriptor becomes
|
/* Wait for millseconds until the given file descriptor becomes
|
||||||
* writable/readable/exception */
|
* writable/readable/exception */
|
||||||
int aeWait(int fd, int mask, long long milliseconds) {
|
int aeWait(int fd, int mask, long long milliseconds) {
|
||||||
struct timeval tv;
|
struct pollfd pfd;
|
||||||
fd_set rfds, wfds, efds;
|
|
||||||
int retmask = 0, retval;
|
int retmask = 0, retval;
|
||||||
|
|
||||||
tv.tv_sec = milliseconds/1000;
|
memset(&pfd, 0, sizeof(pfd));
|
||||||
tv.tv_usec = (milliseconds%1000)*1000;
|
pfd.fd = fd;
|
||||||
FD_ZERO(&rfds);
|
if (mask & AE_READABLE) pfd.events |= POLLIN;
|
||||||
FD_ZERO(&wfds);
|
if (mask & AE_WRITABLE) pfd.events |= POLLOUT;
|
||||||
FD_ZERO(&efds);
|
|
||||||
|
|
||||||
if (mask & AE_READABLE) FD_SET(fd,&rfds);
|
if ((retval = poll(&pfd, 1, milliseconds))== 1) {
|
||||||
if (mask & AE_WRITABLE) FD_SET(fd,&wfds);
|
if (pfd.revents & POLLIN) retmask |= AE_READABLE;
|
||||||
if ((retval = select(fd+1, &rfds, &wfds, &efds, &tv)) > 0) {
|
if (pfd.revents & POLLOUT) retmask |= AE_WRITABLE;
|
||||||
if (FD_ISSET(fd,&rfds)) retmask |= AE_READABLE;
|
|
||||||
if (FD_ISSET(fd,&wfds)) retmask |= AE_WRITABLE;
|
|
||||||
return retmask;
|
return retmask;
|
||||||
} else {
|
} else {
|
||||||
return retval;
|
return retval;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user