Software /
code /
verse
Comparison
client.lua @ 323:5bf3b13edb80
verse.client: Try to behave better when stream is closed gracefully
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 10 Feb 2013 02:53:03 +0100 |
parent | 282:52b971d9ebc3 |
child | 329:2787e038bea2 |
comparison
equal
deleted
inserted
replaced
322:819b35b8fcf6 | 323:5bf3b13edb80 |
---|---|
30 end | 30 end |
31 return true; | 31 return true; |
32 end | 32 end |
33 | 33 |
34 function stream_callbacks.streamclosed(stream) | 34 function stream_callbacks.streamclosed(stream) |
35 return stream:event("closed"); | 35 if not stream.notopen then |
36 stream:send("</stream:stream>"); | |
37 stream.notopen = true; | |
38 end | |
39 stream:event("closed"); | |
40 return stream:close("stream closed") | |
36 end | 41 end |
37 | 42 |
38 function stream_callbacks.handlestanza(stream, stanza) | 43 function stream_callbacks.handlestanza(stream, stanza) |
39 if stanza.attr.xmlns == xmlns_stream then | 44 if stanza.attr.xmlns == xmlns_stream then |
40 return stream:event("stream-"..stanza.name, stanza); | 45 return stream:event("stream-"..stanza.name, stanza); |
127 self:hook("session-success", stream_ready, -1) | 132 self:hook("session-success", stream_ready, -1) |
128 self:hook("bind-success", stream_ready, -1); | 133 self:hook("bind-success", stream_ready, -1); |
129 | 134 |
130 local _base_close = self.close; | 135 local _base_close = self.close; |
131 function self:close(reason) | 136 function self:close(reason) |
137 self.close = _base_close; | |
132 if not self.notopen then | 138 if not self.notopen then |
133 self:send("</stream:stream>"); | 139 self:send("</stream:stream>"); |
134 end | 140 self.notopen = true; |
135 return _base_close(self); | 141 else |
142 return self:close(reason); | |
143 end | |
136 end | 144 end |
137 | 145 |
138 local function start_connect() | 146 local function start_connect() |
139 -- Initialise connection | 147 -- Initialise connection |
140 self:connect(self.connect_host or self.host, self.connect_port or 5222); | 148 self:connect(self.connect_host or self.host, self.connect_port or 5222); |