Software /
code /
prosody
Comparison
net/server_event.lua @ 4962:1d8fb12a9b2d
net.server_select, net.server_event: Change semantics of conn:close() - always call ondisconnect (with err == nil), and never close with data in send buffer (i.e. 'now' parameter removed)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 22 Jul 2012 16:54:33 +0100 |
parent | 4907:32b638a8da5b |
child | 4984:724848dfde36 |
comparison
equal
deleted
inserted
replaced
4961:29b24a4028ed | 4962:1d8fb12a9b2d |
---|---|
247 self:_lock( false, true, true ) -- unlock read/write events, but keep interface locked | 247 self:_lock( false, true, true ) -- unlock read/write events, but keep interface locked |
248 self.eventhandshake = addevent( base, self.conn, EV_READWRITE, handshakecallback, cfg.HANDSHAKE_TIMEOUT ) | 248 self.eventhandshake = addevent( base, self.conn, EV_READWRITE, handshakecallback, cfg.HANDSHAKE_TIMEOUT ) |
249 return true | 249 return true |
250 end | 250 end |
251 function interface_mt:_destroy() -- close this interface + events and call last listener | 251 function interface_mt:_destroy() -- close this interface + events and call last listener |
252 debug( "closing client with id:", self.id ) | 252 debug( "closing client with id:", self.id, self.fatalerror ) |
253 self:_lock( true, true, true ) -- first of all, lock the interface to avoid further actions | 253 self:_lock( true, true, true ) -- first of all, lock the interface to avoid further actions |
254 local _ | 254 local _ |
255 _ = self.eventread and self.eventread:close( ) -- close events; this must be called outside of the event callbacks! | 255 _ = self.eventread and self.eventread:close( ) -- close events; this must be called outside of the event callbacks! |
256 if self.type == "client" then | 256 if self.type == "client" then |
257 _ = self.eventwrite and self.eventwrite:close( ) | 257 _ = self.eventwrite and self.eventwrite:close( ) |
326 --vdebug( "register new write event" ) | 326 --vdebug( "register new write event" ) |
327 self.eventwrite = addevent( base, self.conn, EV_WRITE, self.writecallback, cfg.WRITE_TIMEOUT ) | 327 self.eventwrite = addevent( base, self.conn, EV_WRITE, self.writecallback, cfg.WRITE_TIMEOUT ) |
328 end | 328 end |
329 return true | 329 return true |
330 end | 330 end |
331 function interface_mt:close(now) | 331 function interface_mt:close() |
332 if self.nointerface then return nil, "locked"; end | 332 if self.nointerface then return nil, "locked"; end |
333 debug( "try to close client connection with id:", self.id ) | 333 debug( "try to close client connection with id:", self.id ) |
334 if self.type == "client" then | 334 if self.type == "client" then |
335 self.fatalerror = "client to close" | 335 self.fatalerror = "client to close" |
336 if ( not self.eventwrite ) or now then -- try to close immediately | 336 if self.eventwrite then -- wait for incomplete write request |
337 self:_lock( true, true, false ) | |
338 debug "closing delayed until writebuffer is empty" | |
339 return nil, "writebuffer not empty, waiting" | |
340 else -- close now | |
337 self:_lock( true, true, true ) | 341 self:_lock( true, true, true ) |
338 self:_close() | 342 self:_close() |
339 return true | 343 return true |
340 else -- wait for incomplete write request | |
341 self:_lock( true, true, false ) | |
342 debug "closing delayed until writebuffer is empty" | |
343 return nil, "writebuffer not empty, waiting" | |
344 end | 344 end |
345 else | 345 else |
346 debug( "try to close server with id:", tostring(self.id), "args:", tostring(now) ) | 346 debug( "try to close server with id:", tostring(self.id)) |
347 self.fatalerror = "server to close" | 347 self.fatalerror = "server to close" |
348 self:_lock( true ) | 348 self:_lock( true ) |
349 self:_close( 0 ) -- add new event to remove the server interface | 349 self:_close( 0 ) -- add new event to remove the server interface |
350 return true | 350 return true |
351 end | 351 end |