diff -r 3c3cc6d75814 -r 36f5bf718d3c clix.lua --- a/clix.lua Wed Sep 15 16:54:21 2010 +0100 +++ b/clix.lua Tue Dec 14 20:18:56 2010 +0000 @@ -101,7 +101,7 @@ local _real_close = conn.close; function conn:close() conn:debug("Delaying close..."); - conn:hook("drained", function () + local function close_conn() local function do_close() if _real_close then conn:debug("Closing now..."); @@ -116,7 +116,12 @@ else do_close(); end - end); + end + if conn.conn:bufferlen() == 0 then + close_conn(); + else + conn:hook("drained", close_conn); + end end -- /COMPAT