# HG changeset patch # User jbe # Date 1428625494 -7200 # Node ID 2ab19e15aa6bd19859afbb77c70849cc9d75f23a # Parent 7014436d88ea9c27eddb73c479cb67a589a4fe5f Proper marking I/O handles as closed and finished diff -r 7014436d88ea -r 2ab19e15aa6b moonbridge_io.c --- a/moonbridge_io.c Fri Apr 10 00:33:07 2015 +0200 +++ b/moonbridge_io.c Fri Apr 10 02:24:54 2015 +0200 @@ -396,7 +396,10 @@ if (handle->writeleft) { lua_pushcfunction(L, moonbr_io_flush); lua_pushvalue(L, 1); - lua_call(L, 1, 2); + if (lua_pcall(L, 1, 2, 0)) { + handle->finished = 1; + lua_error(L); + } if (!lua_toboolean(L, -2)) { handle->finished = 1; return 2; @@ -428,11 +431,16 @@ moonbr_io_handle_t *handle; handle = luaL_checkudata(L, 1, MOONBR_IO_HANDLE_MT_REGKEY); if (handle->closed) luaL_error(L, "Attempt to close a closed I/O handle"); + handle->closed = 1; if (!reset) { if (handle->writeleft) { lua_pushcfunction(L, moonbr_io_flush); lua_pushvalue(L, 1); - lua_call(L, 1, 2); + if (lua_pcall(L, 1, 2, 0)) { + close(handle->fd); + handle->fd = -1; + lua_error(L); + } if (!lua_toboolean(L, -2)) { close(handle->fd); handle->fd = -1;