moonbridge

changeset 109:a14e0eb8598b

Catching state-related errors properly in moonbridge_io.poll(...)
author jbe
date Thu Apr 09 18:23:55 2015 +0200 (2015-04-09)
parents 110493d29f90
children 0daa33d9a147
files moonbridge_io.c
line diff
     1.1 --- a/moonbridge_io.c	Thu Apr 09 16:38:16 2015 +0200
     1.2 +++ b/moonbridge_io.c	Thu Apr 09 18:23:55 2015 +0200
     1.3 @@ -861,8 +861,12 @@
     1.4        if (lua_toboolean(L, -1)) {
     1.5          handle = luaL_testudata(L, -2, MOONBR_IO_HANDLE_MT_REGKEY);
     1.6          if (handle) {
     1.7 +          if (handle->closed) luaL_error(L, "Attempt to poll a closed connection");
     1.8            fd = handle->fd;
     1.9 -          if (fd < 0) luaL_error(L, "Handle in illegal state");  /* TODO: EOF simulation with finishing local sockets */
    1.10 +          if (fd < 0) {  /* fake EOF to simulate shutdown */
    1.11 +            lua_pushboolean(L, 1);
    1.12 +            return 1;
    1.13 +          }
    1.14          } else {
    1.15            listener = luaL_testudata(L, -2, MOONBR_IO_LISTENER_MT_REGKEY);
    1.16            if (listener) {
    1.17 @@ -884,17 +888,14 @@
    1.18        if (lua_toboolean(L, -1)) {
    1.19          handle = luaL_testudata(L, -2, MOONBR_IO_HANDLE_MT_REGKEY);
    1.20          if (handle) {
    1.21 +          if (handle->closed) luaL_error(L, "Attempt to poll a closed connection");
    1.22 +          if (handle->finished) luaL_error(L, "Attempt to write-poll a finished connection");
    1.23            fd = handle->fd;
    1.24 -          if (fd < 0) luaL_error(L, "Handle in illegal state");
    1.25          } else {
    1.26            listener = luaL_testudata(L, -2, MOONBR_IO_LISTENER_MT_REGKEY);
    1.27 -          if (listener) {
    1.28 -            fd = listener->fd;
    1.29 -            if (fd < 0) luaL_error(L, "Attempt to poll a closed listener");
    1.30 -          } else {
    1.31 -            fd = lua_tointegerx(L, -2, &isnum);
    1.32 -            if (!isnum) luaL_error(L, "Expected integer (file descriptor), I/O handle, or listener in table key");
    1.33 -          }
    1.34 +          if (listener) luaL_error(L, "Attempt to write-poll a listener");
    1.35 +          fd = lua_tointegerx(L, -2, &isnum);
    1.36 +          if (!isnum) luaL_error(L, "Expected integer (file descriptor) or I/O handle in table key");
    1.37          }
    1.38          FD_SET(fd, &writefds);
    1.39          if (fd+1 > nfds) nfds = fd+1;

Impressum / About Us