26 lines
675 B
C
26 lines
675 B
C
#include "ae.h"
|
|
#include <string.h>
|
|
#include <poll.h>
|
|
|
|
int aeWait(int fd, int mask, long long milliseconds) {
|
|
struct pollfd pfd;
|
|
int retmask = 0, retval;
|
|
|
|
memset(&pfd, 0, sizeof(pfd));
|
|
pfd.fd = fd;
|
|
if (mask & AE_READABLE) pfd.events |= POLLIN;
|
|
if (mask & AE_WRITABLE) pfd.events |= POLLOUT;
|
|
|
|
if ((retval = poll(&pfd, 1, milliseconds))== 1) {
|
|
if (pfd.revents & POLLIN) retmask |= AE_READABLE;
|
|
if (pfd.revents & POLLOUT) retmask |= AE_WRITABLE;
|
|
if (pfd.revents & POLLERR) retmask |= AE_WRITABLE;
|
|
if (pfd.revents & POLLHUP) retmask |= AE_WRITABLE;
|
|
return retmask;
|
|
} else {
|
|
return retval;
|
|
}
|
|
}
|
|
|
|
|