Skip to content
Snippets Groups Projects
Commit 548024b7 authored by Roman Tsisyk's avatar Roman Tsisyk
Browse files

Fixes for socket.iowait() after daurnimator's review

parent c1f6de3b
No related branches found
No related tags found
No related merge requests found
......@@ -384,24 +384,22 @@ lbox_socket_iowait(struct lua_State *L)
{
if (lua_gettop(L) < 2)
goto usage;
int fh = luaL_optinteger(L, 1, -1);
ev_tstamp timeout = luaL_optnumber(L, 3, TIMEOUT_INFINITY);
if (timeout < 0)
goto usage;
/*
* A special shortcut for gh-1204: if fd and events are nil then
* just sleep. This hack simplifies integration of third-party Lua
* modules with Tarantool event loop.
*/
if (unlikely(lua_isnil(L, 1) && lua_isnil(L, 2))) {
if (unlikely(fh < 0)) {
if (!lua_isnil(L, 2))
goto usage;
/* Just sleep, like poll(0, NULL, timeout) */
fiber_sleep(timeout);
return 0;
}
int fh = lua_tointeger(L, 1);
if (fh < 0)
goto usage;
if (likely(lua_type(L, 2) == LUA_TNUMBER)) {
/* Fast path: `events' is a bitmask of (COIO_READ|COIO_WRITE) */
int events = lua_tointeger(L, 2);
......
......@@ -152,6 +152,10 @@ socket.iowait(s:fd(), 'RW')
---
- RW
...
socket.iowait(s:fd(), 'RW', -100500)
---
- RW
...
s:readable(0)
---
- true
......@@ -176,9 +180,23 @@ s:wait(.01)
---
- RW
...
socket.iowait(nil, nil, -1)
---
...
socket.iowait(nil, nil, 0.0001)
---
...
socket.iowait(-1, nil, 0.0001)
---
...
socket.iowait(nil, 'RW')
---
- error: 'Usage: iowait(fd, 1 | ''r'' | 2 | ''w'' | 3 | ''rw'' [, timeout])'
...
socket.iowait(0, nil)
---
- error: 'Usage: iowait(fd, 1 | ''r'' | 2 | ''w'' | 3 | ''rw'' [, timeout])'
...
handshake = ffi.new('char[128]')
---
...
......
......@@ -49,13 +49,18 @@ socket.iowait(s:fd(), 2)
socket.iowait(s:fd(), '')
socket.iowait(s:fd(), -1)
socket.iowait(s:fd(), 'RW')
socket.iowait(s:fd(), 'RW', -100500)
s:readable(0)
s:errno() > 0
s:error()
s:writable(.00000000000001)
s:writable(0)
s:wait(.01)
socket.iowait(nil, nil, -1)
socket.iowait(nil, nil, 0.0001)
socket.iowait(-1, nil, 0.0001)
socket.iowait(nil, 'RW')
socket.iowait(0, nil)
handshake = ffi.new('char[128]')
-- test sysread with char *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment