Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
3e1e1ac2
Commit
3e1e1ac2
authored
Jan 06, 2012
by
jokea
Committed by
antirez
Apr 06, 2012
Browse files
implement aeWait using poll(2). Fixes issue #267.
parent
70381bbf
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/ae.c
View file @
3e1e1ac2
...
...
@@ -35,6 +35,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <poll.h>
#include <string.h>
#include "ae.h"
...
...
@@ -369,21 +370,17 @@ int aeProcessEvents(aeEventLoop *eventLoop, int flags)
/* Wait for millseconds until the given file descriptor becomes
* writable/readable/exception */
int
aeWait
(
int
fd
,
int
mask
,
long
long
milliseconds
)
{
struct
timeval
tv
;
fd_set
rfds
,
wfds
,
efds
;
struct
pollfd
pfd
;
int
retmask
=
0
,
retval
;
tv
.
tv_sec
=
milliseconds
/
1000
;
tv
.
tv_usec
=
(
milliseconds
%
1000
)
*
1000
;
FD_ZERO
(
&
rfds
);
FD_ZERO
(
&
wfds
);
FD_ZERO
(
&
efds
);
if
(
mask
&
AE_READABLE
)
FD_SET
(
fd
,
&
rfds
);
if
(
mask
&
AE_WRITABLE
)
FD_SET
(
fd
,
&
wfds
);
if
((
retval
=
select
(
fd
+
1
,
&
rfds
,
&
wfds
,
&
efds
,
&
tv
))
>
0
)
{
if
(
FD_ISSET
(
fd
,
&
rfds
))
retmask
|=
AE_READABLE
;
if
(
FD_ISSET
(
fd
,
&
wfds
))
retmask
|=
AE_WRITABLE
;
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
;
return
retmask
;
}
else
{
return
retval
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment