Comparison

net/server_event.lua @ 2599:cc6164d85024

net.server_event: Fixes for traceback with no LuaSec
author Matthew Wild <mwild1@gmail.com>
date Thu, 11 Feb 2010 21:32:49 +0000
parent 2561:e7bec4072c61
child 2638:115104acdd7b
comparison
equal deleted inserted replaced
2598:8a021b304765 2599:cc6164d85024
41 local require = use "require" 41 local require = use "require"
42 local tostring = use "tostring" 42 local tostring = use "tostring"
43 local coroutine = use "coroutine" 43 local coroutine = use "coroutine"
44 local setmetatable = use "setmetatable" 44 local setmetatable = use "setmetatable"
45 45
46 local ssl = use "ssl" or require "ssl" 46 local ssl = use "ssl"
47 local socket = use "socket" or require "socket" 47 local socket = use "socket" or require "socket"
48 48
49 local log = require ("util.logger").init("socket") 49 local log = require ("util.logger").init("socket")
50 50
51 local function debug(...) 51 local function debug(...)
140 self.fatalerror = "connection timeout" 140 self.fatalerror = "connection timeout"
141 self:ontimeout() -- call timeout listener 141 self:ontimeout() -- call timeout listener
142 self:_close() 142 self:_close()
143 debug( "new connection failed. id:", self.id, "error:", self.fatalerror ) 143 debug( "new connection failed. id:", self.id, "error:", self.fatalerror )
144 else 144 else
145 if plainssl then -- start ssl session 145 if plainssl and ssl then -- start ssl session
146 self:starttls() 146 self:starttls()
147 else -- normal connection 147 else -- normal connection
148 self:_start_session( self.listener.onconnect ) 148 self:_start_session( self.listener.onconnect )
149 end 149 end
150 debug( "new connection established. id:", self.id ) 150 debug( "new connection established. id:", self.id )
487 _ip = ip, _port = port, _server = server, _pattern = pattern, 487 _ip = ip, _port = port, _server = server, _pattern = pattern,
488 _serverport = (server and server:port() or nil), 488 _serverport = (server and server:port() or nil),
489 _sslctx = sslctx; -- parameters 489 _sslctx = sslctx; -- parameters
490 _usingssl = false; -- client is using ssl; 490 _usingssl = false; -- client is using ssl;
491 } 491 }
492 if not ssl then interface.starttls = false; end
492 interface.id = tostring(interface):match("%x+$"); 493 interface.id = tostring(interface):match("%x+$");
493 interface.writecallback = function( event ) -- called on write events 494 interface.writecallback = function( event ) -- called on write events
494 --vdebug( "new client write event, id/ip/port:", interface, ip, port ) 495 --vdebug( "new client write event, id/ip/port:", interface, ip, port )
495 if interface.nowriting or ( interface.fatalerror and ( "client to close" ~= interface.fatalerror ) ) then -- leave this event 496 if interface.nowriting or ( interface.fatalerror and ( "client to close" ~= interface.fatalerror ) ) then -- leave this event
496 --vdebug( "leaving this event because:", interface.nowriting or interface.fatalerror ) 497 --vdebug( "leaving this event because:", interface.nowriting or interface.fatalerror )
668 end 669 end
669 local ip, port = client:getpeername( ) 670 local ip, port = client:getpeername( )
670 interface._connections = interface._connections + 1 -- increase connection count 671 interface._connections = interface._connections + 1 -- increase connection count
671 local clientinterface = handleclient( client, ip, port, interface, pattern, listener, nil, sslctx ) 672 local clientinterface = handleclient( client, ip, port, interface, pattern, listener, nil, sslctx )
672 --vdebug( "client id:", clientinterface, "startssl:", startssl ) 673 --vdebug( "client id:", clientinterface, "startssl:", startssl )
673 if sslctx then 674 if ssl and sslctx then
674 clientinterface:starttls(sslctx) 675 clientinterface:starttls(sslctx)
675 else 676 else
676 clientinterface:_start_session( clientinterface.onconnect ) 677 clientinterface:_start_session( clientinterface.onconnect )
677 end 678 end
678 debug( "accepted incoming client connection from:", ip, port ) 679 debug( "accepted incoming client connection from:", ip, port )