Comparison

net/server.lua @ 1785:17c0fb598c97

net.server: Add checking for nil sockets to prevent traceback
author Matthew Wild <mwild1@gmail.com>
date Tue, 18 Aug 2009 15:58:44 +0100
parent 1612:0413aaf9edae
child 1788:45779d67c26c
child 1804:f0f5ff6f82d6
comparison
equal deleted inserted replaced
1770:3e17002221eb 1785:17c0fb598c97
481 _ = handler and handler.close( ) 481 _ = handler and handler.close( )
482 return false 482 return false
483 end 483 end
484 end 484 end
485 local _sendbuffer = function( ) -- this function sends data 485 local _sendbuffer = function( ) -- this function sends data
486 local buffer = table_concat( bufferqueue, "", 1, bufferqueuelen ) 486 local succ, err, byte, buffer, count;
487 local succ, err, byte = send( socket, buffer, 1, bufferlen ) 487 local count;
488 local count = ( succ or byte or 0 ) * STAT_UNIT 488 if socket then
489 sendtraffic = sendtraffic + count 489 buffer = table_concat( bufferqueue, "", 1, bufferqueuelen )
490 _sendtraffic = _sendtraffic + count 490 succ, err, byte = send( socket, buffer, 1, bufferlen )
491 _ = _cleanqueue and clean( bufferqueue ) 491 count = ( succ or byte or 0 ) * STAT_UNIT
492 --out_put( "server.lua: sended '", buffer, "', bytes: ", tostring(succ), ", error: ", tostring(err), ", part: ", tostring(byte), ", to: ", tostring(ip), ":", tostring(clientport) ) 492 sendtraffic = sendtraffic + count
493 _sendtraffic = _sendtraffic + count
494 _ = _cleanqueue and clean( bufferqueue )
495 --out_put( "server.lua: sended '", buffer, "', bytes: ", tostring(succ), ", error: ", tostring(err), ", part: ", tostring(byte), ", to: ", tostring(ip), ":", tostring(clientport) )
496 else
497 succ, err, count = false, "closed", 0;
498 end
493 if succ then -- sending succesful 499 if succ then -- sending succesful
494 bufferqueuelen = 0 500 bufferqueuelen = 0
495 bufferlen = 0 501 bufferlen = 0
496 _sendlistlen = removesocket( _sendlist, socket, _sendlistlen ) -- delete socket from writelist 502 _sendlistlen = removesocket( _sendlist, socket, _sendlistlen ) -- delete socket from writelist
497 _ = needtls and handler.starttls(true) 503 _ = needtls and handler.starttls(true)