Software /
code /
clix
Comparison
clix.lua @ 45:36f5bf718d3c
clix.lua: Close connection immediately rather than delaying if send buffer is empty (thanks Florob)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 14 Dec 2010 20:18:56 +0000 |
parent | 43:1ec64b321834 |
child | 52:95ea1dca92ed |
comparison
equal
deleted
inserted
replaced
44:3c3cc6d75814 | 45:36f5bf718d3c |
---|---|
99 | 99 |
100 -- COMPAT: Tigase discards stanzas sent at the same time as </stream:stream> | 100 -- COMPAT: Tigase discards stanzas sent at the same time as </stream:stream> |
101 local _real_close = conn.close; | 101 local _real_close = conn.close; |
102 function conn:close() | 102 function conn:close() |
103 conn:debug("Delaying close..."); | 103 conn:debug("Delaying close..."); |
104 conn:hook("drained", function () | 104 local function close_conn() |
105 local function do_close() | 105 local function do_close() |
106 if _real_close then | 106 if _real_close then |
107 conn:debug("Closing now..."); | 107 conn:debug("Closing now..."); |
108 local close = _real_close; | 108 local close = _real_close; |
109 _real_close = nil; | 109 _real_close = nil; |
114 if close_delay > 0 then | 114 if close_delay > 0 then |
115 verse.add_task(close_delay, do_close); | 115 verse.add_task(close_delay, do_close); |
116 else | 116 else |
117 do_close(); | 117 do_close(); |
118 end | 118 end |
119 end); | 119 end |
120 if conn.conn:bufferlen() == 0 then | |
121 close_conn(); | |
122 else | |
123 conn:hook("drained", close_conn); | |
124 end | |
120 end | 125 end |
121 -- /COMPAT | 126 -- /COMPAT |
122 | 127 |
123 | 128 |
124 if type(opts.resource) == "string" then | 129 if type(opts.resource) == "string" then |