# HG changeset patch # User jbe # Date 1435018046 -7200 # Node ID 35ea31e45b4319a1dcd20cc7e7555464d5c66f8d # Parent 0b65557320472ac2fe3876bd27f7da2ac4c37d81 Send a TCP RST instead of TCP FIN when a socket gets garbage collected (and hasn't been closed) diff -r 0b6555732047 -r 35ea31e45b43 moonbridge_io.c --- a/moonbridge_io.c Tue Jun 23 02:05:46 2015 +0200 +++ b/moonbridge_io.c Tue Jun 23 02:07:26 2015 +0200 @@ -726,7 +726,7 @@ moonbr_io_handle_t *handle; handle = luaL_checkudata(L, 1, MOONBR_IO_HANDLE_MT_REGKEY); if (handle->fd >= 0) { - lua_pushcfunction(L, moonbr_io_close); + lua_pushcfunction(L, moonbr_io_reset); lua_pushvalue(L, 1); lua_pushinteger(L, 0); lua_call(L, 2, 0); diff -r 0b6555732047 -r 35ea31e45b43 reference.txt --- a/reference.txt Tue Jun 23 02:05:46 2015 +0200 +++ b/reference.txt Tue Jun 23 02:07:26 2015 +0200 @@ -66,6 +66,11 @@ (or drained) before calling socket:close(). Use socket:finish() to send a TCP FIN packet to the peer before waiting for EOF from the peer. +A socket passed to the "connect" handler will be closed automatically if it was +not closed by the "connect" handler and if the "connect" handler returns +normally (i.e. without throwing an error). If the "connect" handler throws an +error, then the socket will be reset. See socket:reset(). + ### socket:drain(maxlen, terminator) @@ -232,8 +237,10 @@ ### socket:reset() -Alias for socket:close(0). Closes the socket connection by sending a TCP RST -packet if possible to indicate error condition. +Alias for socket:close(). Closes the socket connection by sending a TCP RST +packet if possible to indicate error condition. This is the default operation +when a socket handle gets garbage collected or the process is terminated +abnormally. Returns true on success, or nil (as first return value) plus error message (as second return value) in case of an I/O error. Using this method on sockets that