Comparison

net/server.lua @ 741:97577b6c07ca

server.lua: Comment out unnecessary or very verbose logging, and log the rest as debug level
author Matthew Wild <mwild1@gmail.com>
date Sat, 17 Jan 2009 14:57:21 +0000
parent 740:cc25d75b4027
child 770:bddf52121908
comparison
equal deleted inserted replaced
740:cc25d75b4027 741:97577b6c07ca
17 tbl[ i ] = nil 17 tbl[ i ] = nil
18 end 18 end
19 end 19 end
20 20
21 local log, table_concat = require ("util.logger").init("socket"), table.concat; 21 local log, table_concat = require ("util.logger").init("socket"), table.concat;
22 local out_put = function () end 22 local out_put = function (...) return log("debug", table_concat{...}); end
23 local out_error = function (...) return log("warn", table_concat{...}); end 23 local out_error = function (...) return log("warn", table_concat{...}); end
24 local mem_free = collectgarbage 24 local mem_free = collectgarbage
25 25
26 ----------------------------------// DECLARATION //-- 26 ----------------------------------// DECLARATION //--
27 27
431 end 431 end
432 local count = len * STAT_UNIT 432 local count = len * STAT_UNIT
433 readtraffic = readtraffic + count 433 readtraffic = readtraffic + count
434 _readtraffic = _readtraffic + count 434 _readtraffic = _readtraffic + count
435 _readtimes[ handler ] = _currenttime 435 _readtimes[ handler ] = _currenttime
436 out_put( "server.lua: read data '", buffer, "', error: ", err ) 436 --out_put( "server.lua: read data '", buffer, "', error: ", err )
437 return dispatch( handler, buffer, err ) 437 return dispatch( handler, buffer, err )
438 else -- connections was closed or fatal error 438 else -- connections was closed or fatal error
439 out_put( "server.lua: client ", ip, ":", clientport, " error: ", err ) 439 out_put( "server.lua: client ", ip, ":", clientport, " error: ", err )
440 fatalerror = true 440 fatalerror = true
441 disconnect( handler, err ) 441 disconnect( handler, err )
448 local succ, err, byte = send( socket, buffer, 1, bufferlen ) 448 local succ, err, byte = send( socket, buffer, 1, bufferlen )
449 local count = ( succ or byte or 0 ) * STAT_UNIT 449 local count = ( succ or byte or 0 ) * STAT_UNIT
450 sendtraffic = sendtraffic + count 450 sendtraffic = sendtraffic + count
451 _sendtraffic = _sendtraffic + count 451 _sendtraffic = _sendtraffic + count
452 _ = _cleanqueue and clean( bufferqueue ) 452 _ = _cleanqueue and clean( bufferqueue )
453 out_put( "server.lua: sended '", buffer, "', bytes: ", succ, ", error: ", err, ", part: ", byte, ", to: ", ip, ":", clientport ) 453 --out_put( "server.lua: sended '", buffer, "', bytes: ", succ, ", error: ", err, ", part: ", byte, ", to: ", ip, ":", clientport )
454 if succ then -- sending succesful 454 if succ then -- sending succesful
455 bufferqueuelen = 0 455 bufferqueuelen = 0
456 bufferlen = 0 456 bufferlen = 0
457 _sendlistlen = removesocket( _sendlist, socket, _sendlistlen ) -- delete socket from writelist 457 _sendlistlen = removesocket( _sendlist, socket, _sendlistlen ) -- delete socket from writelist
458 _ = needtls and handler.starttls(true) 458 _ = needtls and handler.starttls(true)
481 local handshake = coroutine_wrap( function( client ) -- create handshake coroutine 481 local handshake = coroutine_wrap( function( client ) -- create handshake coroutine
482 local err 482 local err
483 for i = 1, 10 do -- 10 handshake attemps 483 for i = 1, 10 do -- 10 handshake attemps
484 _, err = client:dohandshake( ) 484 _, err = client:dohandshake( )
485 if not err then 485 if not err then
486 out_put( "server.lua: ssl handshake done" ) 486 --out_put( "server.lua: ssl handshake done" )
487 _sendlistlen = ( wrote and removesocket( _sendlist, socket, _sendlistlen ) ) or _sendlistlen 487 _sendlistlen = ( wrote and removesocket( _sendlist, socket, _sendlistlen ) ) or _sendlistlen
488 handler.readbuffer = _readbuffer -- when handshake is done, replace the handshake function with regular functions 488 handler.readbuffer = _readbuffer -- when handshake is done, replace the handshake function with regular functions
489 handler.sendbuffer = _sendbuffer 489 handler.sendbuffer = _sendbuffer
490 --return dispatch( handler ) 490 --return dispatch( handler )
491 return true 491 return true
504 handler.close( true ) -- forced disconnect 504 handler.close( true ) -- forced disconnect
505 return false -- handshake failed 505 return false -- handshake failed
506 end 506 end
507 ) 507 )
508 if startssl then -- ssl now? 508 if startssl then -- ssl now?
509 out_put("server.lua: ", "starting ssl handshake") 509 --out_put("server.lua: ", "starting ssl handshake")
510 local err 510 local err
511 socket, err = ssl_wrap( socket, sslctx ) -- wrap socket 511 socket, err = ssl_wrap( socket, sslctx ) -- wrap socket
512 if err then 512 if err then
513 out_put( "server.lua: ssl error: ", err ) 513 out_put( "server.lua: ssl error: ", err )
514 mem_free( ) 514 mem_free( )
519 handler.sendbuffer = handshake 519 handler.sendbuffer = handshake
520 handshake( socket ) -- do handshake 520 handshake( socket ) -- do handshake
521 else 521 else
522 handler.starttls = function( now ) 522 handler.starttls = function( now )
523 if not now then 523 if not now then
524 out_put "server.lua: we need to do tls, but delaying until later" 524 --out_put "server.lua: we need to do tls, but delaying until later"
525 needtls = true 525 needtls = true
526 return 526 return
527 end 527 end
528 out_put( "server.lua: attempting to start tls on " .. tostring( socket ) ) 528 --out_put( "server.lua: attempting to start tls on " .. tostring( socket ) )
529 local oldsocket, err = socket 529 local oldsocket, err = socket
530 socket, err = ssl_wrap( socket, sslctx ) -- wrap socket 530 socket, err = ssl_wrap( socket, sslctx ) -- wrap socket
531 out_put( "server.lua: sslwrapped socket is " .. tostring( socket ) ) 531 --out_put( "server.lua: sslwrapped socket is " .. tostring( socket ) )
532 if err then 532 if err then
533 out_put( "server.lua: error while starting tls on client: ", err ) 533 out_put( "server.lua: error while starting tls on client: ", err )
534 return nil, err -- fatal error 534 return nil, err -- fatal error
535 end 535 end
536 536
613 613
614 ----------------------------------// PUBLIC //-- 614 ----------------------------------// PUBLIC //--
615 615
616 addserver = function( listeners, port, addr, pattern, sslctx, maxconnections, startssl ) -- this function provides a way for other scripts to reg a server 616 addserver = function( listeners, port, addr, pattern, sslctx, maxconnections, startssl ) -- this function provides a way for other scripts to reg a server
617 local err 617 local err
618 out_put("server.lua: autossl on ", port, " is ", startssl) 618 --out_put("server.lua: autossl on ", port, " is ", startssl)
619 if type( listeners ) ~= "table" then 619 if type( listeners ) ~= "table" then
620 err = "invalid listener table" 620 err = "invalid listener table"
621 end 621 end
622 if not type( port ) == "number" or not ( port >= 0 and port <= 65535 ) then 622 if not type( port ) == "number" or not ( port >= 0 and port <= 65535 ) then
623 err = "invalid port" 623 err = "invalid port"