Comparison

net/server_select.lua @ 5337:c22dd451487f

net.server_select: Use # operator instead of string.len
author Kim Alvefur <zash@zash.se>
date Fri, 01 Mar 2013 11:11:05 +0100
parent 5331:ffa740b4f08d
child 5338:3df649ec43ea
comparison
equal deleted inserted replaced
5336:eeb24f1e2c84 5337:c22dd451487f
45 45
46 local os_difftime = os.difftime 46 local os_difftime = os.difftime
47 local math_min = math.min 47 local math_min = math.min
48 local math_huge = math.huge 48 local math_huge = math.huge
49 local table_concat = table.concat 49 local table_concat = table.concat
50 local string_len = string.len
51 local string_sub = string.sub 50 local string_sub = string.sub
52 local coroutine_wrap = coroutine.wrap 51 local coroutine_wrap = coroutine.wrap
53 local coroutine_yield = coroutine.yield 52 local coroutine_yield = coroutine.yield
54 53
55 --// extern libs //-- 54 --// extern libs //--
404 end 403 end
405 handler.clientport = function( ) 404 handler.clientport = function( )
406 return clientport 405 return clientport
407 end 406 end
408 local write = function( self, data ) 407 local write = function( self, data )
409 bufferlen = bufferlen + string_len( data ) 408 bufferlen = bufferlen + #data
410 if bufferlen > maxsendlen then 409 if bufferlen > maxsendlen then
411 _closelist[ handler ] = "send buffer exceeded" -- cannot close the client at the moment, have to wait to the end of the cycle 410 _closelist[ handler ] = "send buffer exceeded" -- cannot close the client at the moment, have to wait to the end of the cycle
412 handler.write = idfalse -- dont write anymore 411 handler.write = idfalse -- dont write anymore
413 return false 412 return false
414 elseif socket and not _sendlist[ socket ] then 413 elseif socket and not _sendlist[ socket ] then
486 end 485 end
487 local _readbuffer = function( ) -- this function reads data 486 local _readbuffer = function( ) -- this function reads data
488 local buffer, err, part = receive( socket, pattern ) -- receive buffer with "pattern" 487 local buffer, err, part = receive( socket, pattern ) -- receive buffer with "pattern"
489 if not err or (err == "wantread" or err == "timeout") then -- received something 488 if not err or (err == "wantread" or err == "timeout") then -- received something
490 local buffer = buffer or part or "" 489 local buffer = buffer or part or ""
491 local len = string_len( buffer ) 490 local len = #buffer
492 if len > maxreadlen then 491 if len > maxreadlen then
493 handler:close( "receive buffer exceeded" ) 492 handler:close( "receive buffer exceeded" )
494 return false 493 return false
495 end 494 end
496 local count = len * STAT_UNIT 495 local count = len * STAT_UNIT