moonbridge
changeset 116:2ab19e15aa6b
Proper marking I/O handles as closed and finished
author | jbe |
---|---|
date | Fri Apr 10 02:24:54 2015 +0200 (2015-04-10) |
parents | 7014436d88ea |
children | d8469c1039e6 |
files | moonbridge_io.c |
line diff
1.1 --- a/moonbridge_io.c Fri Apr 10 00:33:07 2015 +0200 1.2 +++ b/moonbridge_io.c Fri Apr 10 02:24:54 2015 +0200 1.3 @@ -396,7 +396,10 @@ 1.4 if (handle->writeleft) { 1.5 lua_pushcfunction(L, moonbr_io_flush); 1.6 lua_pushvalue(L, 1); 1.7 - lua_call(L, 1, 2); 1.8 + if (lua_pcall(L, 1, 2, 0)) { 1.9 + handle->finished = 1; 1.10 + lua_error(L); 1.11 + } 1.12 if (!lua_toboolean(L, -2)) { 1.13 handle->finished = 1; 1.14 return 2; 1.15 @@ -428,11 +431,16 @@ 1.16 moonbr_io_handle_t *handle; 1.17 handle = luaL_checkudata(L, 1, MOONBR_IO_HANDLE_MT_REGKEY); 1.18 if (handle->closed) luaL_error(L, "Attempt to close a closed I/O handle"); 1.19 + handle->closed = 1; 1.20 if (!reset) { 1.21 if (handle->writeleft) { 1.22 lua_pushcfunction(L, moonbr_io_flush); 1.23 lua_pushvalue(L, 1); 1.24 - lua_call(L, 1, 2); 1.25 + if (lua_pcall(L, 1, 2, 0)) { 1.26 + close(handle->fd); 1.27 + handle->fd = -1; 1.28 + lua_error(L); 1.29 + } 1.30 if (!lua_toboolean(L, -2)) { 1.31 close(handle->fd); 1.32 handle->fd = -1;