equal
deleted
inserted
replaced
57 } Lpoll_state; |
57 } Lpoll_state; |
58 |
58 |
59 /* |
59 /* |
60 * Add an FD to be watched |
60 * Add an FD to be watched |
61 */ |
61 */ |
62 int Ladd(lua_State *L) { |
62 static int Ladd(lua_State *L) { |
63 struct Lpoll_state *state = luaL_checkudata(L, 1, STATE_MT); |
63 struct Lpoll_state *state = luaL_checkudata(L, 1, STATE_MT); |
64 int fd = luaL_checkinteger(L, 2); |
64 int fd = luaL_checkinteger(L, 2); |
65 |
65 |
66 int wantread = lua_toboolean(L, 3); |
66 int wantread = lua_toboolean(L, 3); |
67 int wantwrite = lua_toboolean(L, 4); |
67 int wantwrite = lua_toboolean(L, 4); |
135 } |
135 } |
136 |
136 |
137 /* |
137 /* |
138 * Set events to watch for, readable and/or writable |
138 * Set events to watch for, readable and/or writable |
139 */ |
139 */ |
140 int Lset(lua_State *L) { |
140 static int Lset(lua_State *L) { |
141 struct Lpoll_state *state = luaL_checkudata(L, 1, STATE_MT); |
141 struct Lpoll_state *state = luaL_checkudata(L, 1, STATE_MT); |
142 int fd = luaL_checkinteger(L, 2); |
142 int fd = luaL_checkinteger(L, 2); |
143 |
143 |
144 #ifdef USE_EPOLL |
144 #ifdef USE_EPOLL |
145 |
145 |
198 } |
198 } |
199 |
199 |
200 /* |
200 /* |
201 * Remove FDs |
201 * Remove FDs |
202 */ |
202 */ |
203 int Ldel(lua_State *L) { |
203 static int Ldel(lua_State *L) { |
204 struct Lpoll_state *state = luaL_checkudata(L, 1, STATE_MT); |
204 struct Lpoll_state *state = luaL_checkudata(L, 1, STATE_MT); |
205 int fd = luaL_checkinteger(L, 2); |
205 int fd = luaL_checkinteger(L, 2); |
206 |
206 |
207 #ifdef USE_EPOLL |
207 #ifdef USE_EPOLL |
208 |
208 |
245 |
245 |
246 |
246 |
247 /* |
247 /* |
248 * Check previously manipulated event state for FDs ready for reading or writing |
248 * Check previously manipulated event state for FDs ready for reading or writing |
249 */ |
249 */ |
250 int Lpushevent(lua_State *L, struct Lpoll_state *state) { |
250 static int Lpushevent(lua_State *L, struct Lpoll_state *state) { |
251 #ifdef USE_EPOLL |
251 #ifdef USE_EPOLL |
252 |
252 |
253 if(state->processed > 0) { |
253 if(state->processed > 0) { |
254 state->processed--; |
254 state->processed--; |
255 struct epoll_event event = state->events[state->processed]; |
255 struct epoll_event event = state->events[state->processed]; |
279 } |
279 } |
280 |
280 |
281 /* |
281 /* |
282 * Wait for event |
282 * Wait for event |
283 */ |
283 */ |
284 int Lwait(lua_State *L) { |
284 static int Lwait(lua_State *L) { |
285 struct Lpoll_state *state = luaL_checkudata(L, 1, STATE_MT); |
285 struct Lpoll_state *state = luaL_checkudata(L, 1, STATE_MT); |
286 |
286 |
287 int ret = Lpushevent(L, state); |
287 int ret = Lpushevent(L, state); |
288 |
288 |
289 if(ret != 0) { |
289 if(ret != 0) { |
342 |
342 |
343 #ifdef USE_EPOLL |
343 #ifdef USE_EPOLL |
344 /* |
344 /* |
345 * Return Epoll FD |
345 * Return Epoll FD |
346 */ |
346 */ |
347 int Lgetfd(lua_State *L) { |
347 static int Lgetfd(lua_State *L) { |
348 struct Lpoll_state *state = luaL_checkudata(L, 1, STATE_MT); |
348 struct Lpoll_state *state = luaL_checkudata(L, 1, STATE_MT); |
349 lua_pushinteger(L, state->epoll_fd); |
349 lua_pushinteger(L, state->epoll_fd); |
350 return 1; |
350 return 1; |
351 } |
351 } |
352 |
352 |
353 /* |
353 /* |
354 * Close epoll FD |
354 * Close epoll FD |
355 */ |
355 */ |
356 int Lgc(lua_State *L) { |
356 static int Lgc(lua_State *L) { |
357 struct Lpoll_state *state = luaL_checkudata(L, 1, STATE_MT); |
357 struct Lpoll_state *state = luaL_checkudata(L, 1, STATE_MT); |
358 |
358 |
359 if(state->epoll_fd == -1) { |
359 if(state->epoll_fd == -1) { |
360 return 0; |
360 return 0; |
361 } |
361 } |
373 #endif |
373 #endif |
374 |
374 |
375 /* |
375 /* |
376 * String representation |
376 * String representation |
377 */ |
377 */ |
378 int Ltos(lua_State *L) { |
378 static int Ltos(lua_State *L) { |
379 struct Lpoll_state *state = luaL_checkudata(L, 1, STATE_MT); |
379 struct Lpoll_state *state = luaL_checkudata(L, 1, STATE_MT); |
380 lua_pushfstring(L, "%s: %p", STATE_MT, state); |
380 lua_pushfstring(L, "%s: %p", STATE_MT, state); |
381 return 1; |
381 return 1; |
382 } |
382 } |
383 |
383 |
384 /* |
384 /* |
385 * Create a new context |
385 * Create a new context |
386 */ |
386 */ |
387 int Lnew(lua_State *L) { |
387 static int Lnew(lua_State *L) { |
388 /* Allocate state */ |
388 /* Allocate state */ |
389 Lpoll_state *state = lua_newuserdata(L, sizeof(Lpoll_state)); |
389 Lpoll_state *state = lua_newuserdata(L, sizeof(Lpoll_state)); |
390 luaL_setmetatable(L, STATE_MT); |
390 luaL_setmetatable(L, STATE_MT); |
391 |
391 |
392 /* Initialize state */ |
392 /* Initialize state */ |