Comparison

net/server_select.lua @ 2728:3f8d9319d4a3

net.server_select: Fix calling method of some handler.close()s
author Matthew Wild <mwild1@gmail.com>
date Mon, 01 Mar 2010 18:06:54 +0000
parent 2598:8a021b304765
child 2732:dabdc56561f9
comparison
equal deleted inserted replaced
2726:1b9179e04233 2728:3f8d9319d4a3
433 if not err or (err == "wantread" or err == "timeout") or string_len(part) > 0 then -- received something 433 if not err or (err == "wantread" or err == "timeout") or string_len(part) > 0 then -- received something
434 local buffer = buffer or part or "" 434 local buffer = buffer or part or ""
435 local len = string_len( buffer ) 435 local len = string_len( buffer )
436 if len > maxreadlen then 436 if len > maxreadlen then
437 disconnect( handler, "receive buffer exceeded" ) 437 disconnect( handler, "receive buffer exceeded" )
438 handler.close( true ) 438 handler:close( true )
439 return false 439 return false
440 end 440 end
441 local count = len * STAT_UNIT 441 local count = len * STAT_UNIT
442 readtraffic = readtraffic + count 442 readtraffic = readtraffic + count
443 _readtraffic = _readtraffic + count 443 _readtraffic = _readtraffic + count
446 return dispatch( handler, buffer, err ) 446 return dispatch( handler, buffer, err )
447 else -- connections was closed or fatal error 447 else -- connections was closed or fatal error
448 out_put( "server.lua: client ", tostring(ip), ":", tostring(clientport), " read error: ", tostring(err) ) 448 out_put( "server.lua: client ", tostring(ip), ":", tostring(clientport), " read error: ", tostring(err) )
449 fatalerror = true 449 fatalerror = true
450 disconnect( handler, err ) 450 disconnect( handler, err )
451 _ = handler and handler.close( ) 451 _ = handler and handler:close( )
452 return false 452 return false
453 end 453 end
454 end 454 end
455 local _sendbuffer = function( ) -- this function sends data 455 local _sendbuffer = function( ) -- this function sends data
456 local succ, err, byte, buffer, count; 456 local succ, err, byte, buffer, count;
470 bufferqueuelen = 0 470 bufferqueuelen = 0
471 bufferlen = 0 471 bufferlen = 0
472 _sendlistlen = removesocket( _sendlist, socket, _sendlistlen ) -- delete socket from writelist 472 _sendlistlen = removesocket( _sendlist, socket, _sendlistlen ) -- delete socket from writelist
473 _ = needtls and handler:starttls(nil, true) 473 _ = needtls and handler:starttls(nil, true)
474 _writetimes[ handler ] = nil 474 _writetimes[ handler ] = nil
475 _ = toclose and handler.close( ) 475 _ = toclose and handlerclose( )
476 return true 476 return true
477 elseif byte and ( err == "timeout" or err == "wantwrite" ) then -- want write 477 elseif byte and ( err == "timeout" or err == "wantwrite" ) then -- want write
478 buffer = string_sub( buffer, byte + 1, bufferlen ) -- new buffer 478 buffer = string_sub( buffer, byte + 1, bufferlen ) -- new buffer
479 bufferqueue[ 1 ] = buffer -- insert new buffer in queue 479 bufferqueue[ 1 ] = buffer -- insert new buffer in queue
480 bufferqueuelen = 1 480 bufferqueuelen = 1
483 return true 483 return true
484 else -- connection was closed during sending or fatal error 484 else -- connection was closed during sending or fatal error
485 out_put( "server.lua: client ", tostring(ip), ":", tostring(clientport), " write error: ", tostring(err) ) 485 out_put( "server.lua: client ", tostring(ip), ":", tostring(clientport), " write error: ", tostring(err) )
486 fatalerror = true 486 fatalerror = true
487 disconnect( handler, err ) 487 disconnect( handler, err )
488 _ = handler and handler.close( ) 488 _ = handler and handler:close( )
489 return false 489 return false
490 end 490 end
491 end 491 end
492 492
493 -- Set the sslctx 493 -- Set the sslctx