Comparison

net/server_event.lua @ 5276:8a207a7e52d3

net.server_event: Remove comments about not closing event handlers from within callbacks, fixed in luaevent
author Kim Alvefur <zash@zash.se>
date Fri, 28 Dec 2012 14:25:11 +0100
parent 5018:eb8211b65e96
child 5277:8585f3cc4976
comparison
equal deleted inserted replaced
5274:0d08c0965824 5276:8a207a7e52d3
4 server.lua based on lua/libevent by blastbeat 4 server.lua based on lua/libevent by blastbeat
5 5
6 notes: 6 notes:
7 -- when using luaevent, never register 2 or more EV_READ at one socket, same for EV_WRITE 7 -- when using luaevent, never register 2 or more EV_READ at one socket, same for EV_WRITE
8 -- you cant even register a new EV_READ/EV_WRITE callback inside another one 8 -- you cant even register a new EV_READ/EV_WRITE callback inside another one
9 -- never call eventcallback:close( ) from inside eventcallback
10 -- to do some of the above, use timeout events or something what will called from outside 9 -- to do some of the above, use timeout events or something what will called from outside
11 -- dont let garbagecollect eventcallbacks, as long they are running 10 -- dont let garbagecollect eventcallbacks, as long they are running
12 -- when using luasec, there are 4 cases of timeout errors: wantread or wantwrite during reading or writing 11 -- when using luasec, there are 4 cases of timeout errors: wantread or wantwrite during reading or writing
13 12
14 --]] 13 --]]
246 end 245 end
247 function interface_mt:_destroy() -- close this interface + events and call last listener 246 function interface_mt:_destroy() -- close this interface + events and call last listener
248 debug( "closing client with id:", self.id, self.fatalerror ) 247 debug( "closing client with id:", self.id, self.fatalerror )
249 self:_lock( true, true, true ) -- first of all, lock the interface to avoid further actions 248 self:_lock( true, true, true ) -- first of all, lock the interface to avoid further actions
250 local _ 249 local _
251 _ = self.eventread and self.eventread:close( ) -- close events; this must be called outside of the event callbacks! 250 _ = self.eventread and self.eventread:close( )
252 if self.type == "client" then 251 if self.type == "client" then
253 _ = self.eventwrite and self.eventwrite:close( ) 252 _ = self.eventwrite and self.eventwrite:close( )
254 _ = self.eventhandshake and self.eventhandshake:close( ) 253 _ = self.eventhandshake and self.eventhandshake:close( )
255 _ = self.eventstarthandshake and self.eventstarthandshake:close( ) 254 _ = self.eventstarthandshake and self.eventstarthandshake:close( )
256 _ = self.eventconnect and self.eventconnect:close( ) 255 _ = self.eventconnect and self.eventconnect:close( )
257 _ = self.eventsession and self.eventsession:close( ) 256 _ = self.eventsession and self.eventsession:close( )
258 _ = self.eventwritetimeout and self.eventwritetimeout:close( ) 257 _ = self.eventwritetimeout and self.eventwritetimeout:close( )
259 _ = self.eventreadtimeout and self.eventreadtimeout:close( ) 258 _ = self.eventreadtimeout and self.eventreadtimeout:close( )
260 _ = self.ondisconnect and self:ondisconnect( self.fatalerror ~= "client to close" and self.fatalerror) -- call ondisconnect listener (wont be the case if handshake failed on connect) 259 _ = self.ondisconnect and self:ondisconnect( self.fatalerror ~= "client to close" and self.fatalerror) -- call ondisconnect listener (wont be the case if handshake failed on connect)
261 _ = self.conn and self.conn:close( ) -- close connection, must also be called outside of any socket registered events! 260 _ = self.conn and self.conn:close( ) -- close connection
262 _ = self._server and self._server:counter(-1); 261 _ = self._server and self._server:counter(-1);
263 self.eventread, self.eventwrite = nil, nil 262 self.eventread, self.eventwrite = nil, nil
264 self.eventstarthandshake, self.eventhandshake, self.eventclose = nil, nil, nil 263 self.eventstarthandshake, self.eventhandshake, self.eventclose = nil, nil, nil
265 self.readcallback, self.writecallback = nil, nil 264 self.readcallback, self.writecallback = nil, nil
266 else 265 else
340 end 339 end
341 else 340 else
342 debug( "try to close server with id:", tostring(self.id)) 341 debug( "try to close server with id:", tostring(self.id))
343 self.fatalerror = "server to close" 342 self.fatalerror = "server to close"
344 self:_lock( true ) 343 self:_lock( true )
345 self:_close( 0 ) -- add new event to remove the server interface 344 self:_close( 0 )
346 return true 345 return true
347 end 346 end
348 end 347 end
349 348
350 function interface_mt:socket() 349 function interface_mt:socket()