Comparison

net/server_event.lua @ 2122:dd1da05568e4

net.server_event: Obey nowriting/nointerface for locks in interface methods
author Matthew Wild <mwild1@gmail.com>
date Sun, 22 Nov 2009 04:04:04 +0000
parent 2121:3a5ed91a9f27
child 2123:f7b589f798af
comparison
equal deleted inserted replaced
2121:3a5ed91a9f27 2122:dd1da05568e4
288 return self._connections 288 return self._connections
289 end 289 end
290 290
291 -- Public methods 291 -- Public methods
292 function interface_mt:write(data) 292 function interface_mt:write(data)
293 if self.nowriting then return nil, "locked" end
293 vdebug( "try to send data to client, id/data:", self.id, data ) 294 vdebug( "try to send data to client, id/data:", self.id, data )
294 data = tostring( data ) 295 data = tostring( data )
295 local len = string_len( data ) 296 local len = string_len( data )
296 local total = len + self.writebufferlen 297 local total = len + self.writebufferlen
297 if total > cfg.MAX_SEND_LENGTH then -- check buffer length 298 if total > cfg.MAX_SEND_LENGTH then -- check buffer length
306 self.eventwrite = addevent( base, self.conn, EV_WRITE, self.writecallback, cfg.WRITE_TIMEOUT ) 307 self.eventwrite = addevent( base, self.conn, EV_WRITE, self.writecallback, cfg.WRITE_TIMEOUT )
307 end 308 end
308 return true 309 return true
309 end 310 end
310 function interface_mt:close(now) 311 function interface_mt:close(now)
312 if self.nointerface then return nil, "locked"; end
311 debug( "try to close client connection with id:", self.id ) 313 debug( "try to close client connection with id:", self.id )
312 if self.type == "client" then 314 if self.type == "client" then
313 self.fatalerror = "client to close" 315 self.fatalerror = "client to close"
314 if ( not self.eventwrite ) or now then -- try to close immediately 316 if ( not self.eventwrite ) or now then -- try to close immediately
315 self:_lock( true, true, true ) 317 self:_lock( true, true, true )