equal
deleted
inserted
replaced
24 |
24 |
25 #ifdef USE_EPOLL |
25 #ifdef USE_EPOLL |
26 #include <unistd.h> |
26 #include <unistd.h> |
27 #include <sys/epoll.h> |
27 #include <sys/epoll.h> |
28 #ifndef MAX_EVENTS |
28 #ifndef MAX_EVENTS |
|
29 /* Maximum number of returned events, retrieved into Lpoll_state */ |
29 #define MAX_EVENTS 256 |
30 #define MAX_EVENTS 256 |
30 #endif |
31 #endif |
31 #endif |
32 #endif |
32 #ifdef USE_POLL |
33 #ifdef USE_POLL |
33 #include <poll.h> |
34 #include <poll.h> |
34 #ifndef MAX_EVENTS |
35 #ifndef MAX_WATCHED |
35 #define MAX_EVENTS 10000 |
36 /* Maximum number of watched sockets, kept in Lpoll_state */ |
|
37 #define MAX_WATCHED 10000 |
36 #endif |
38 #endif |
37 #endif |
39 #endif |
38 #ifdef USE_SELECT |
40 #ifdef USE_SELECT |
39 #include <sys/select.h> |
41 #include <sys/select.h> |
40 #endif |
42 #endif |
57 int epoll_fd; |
59 int epoll_fd; |
58 struct epoll_event events[MAX_EVENTS]; |
60 struct epoll_event events[MAX_EVENTS]; |
59 #endif |
61 #endif |
60 #ifdef USE_POLL |
62 #ifdef USE_POLL |
61 nfds_t count; |
63 nfds_t count; |
62 struct pollfd events[MAX_EVENTS]; |
64 struct pollfd events[MAX_WATCHED]; |
63 #endif |
65 #endif |
64 #ifdef USE_SELECT |
66 #ifdef USE_SELECT |
65 fd_set wantread; |
67 fd_set wantread; |
66 fd_set wantwrite; |
68 fd_set wantwrite; |
67 fd_set readable; |
69 fd_set readable; |
118 lua_pushinteger(L, EEXIST); |
120 lua_pushinteger(L, EEXIST); |
119 return 3; |
121 return 3; |
120 } |
122 } |
121 } |
123 } |
122 |
124 |
123 if(state->count >= MAX_EVENTS) { |
125 if(state->count >= MAX_WATCHED) { |
124 luaL_pushfail(L); |
126 luaL_pushfail(L); |
125 lua_pushstring(L, strerror(EMFILE)); |
127 lua_pushstring(L, strerror(EMFILE)); |
126 lua_pushinteger(L, EMFILE); |
128 lua_pushinteger(L, EMFILE); |
127 return 3; |
129 return 3; |
128 } |
130 } |
541 #endif |
543 #endif |
542 #ifdef USE_POLL |
544 #ifdef USE_POLL |
543 state->processed = -1; |
545 state->processed = -1; |
544 state->count = 0; |
546 state->count = 0; |
545 |
547 |
546 for(nfds_t i = 0; i < MAX_EVENTS; i++) { |
548 for(nfds_t i = 0; i < MAX_WATCHED; i++) { |
547 state->events[i].fd = -1; |
549 state->events[i].fd = -1; |
548 state->events[i].events = 0; |
550 state->events[i].events = 0; |
549 state->events[i].revents = 0; |
551 state->events[i].revents = 0; |
550 } |
552 } |
551 |
553 |