diff options
-rw-r--r-- | net/server_event.lua | 7 | ||||
-rw-r--r-- | net/server_select.lua | 10 |
2 files changed, 10 insertions, 7 deletions
diff --git a/net/server_event.lua b/net/server_event.lua index 3afc732b..e79a57d0 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -43,7 +43,7 @@ local tostring = use "tostring" local coroutine = use "coroutine" local setmetatable = use "setmetatable" -local ssl = use "ssl" or require "ssl" +local ssl = use "ssl" local socket = use "socket" or require "socket" local log = require ("util.logger").init("socket") @@ -142,7 +142,7 @@ do self:_close() debug( "new connection failed. id:", self.id, "error:", self.fatalerror ) else - if plainssl then -- start ssl session + if plainssl and ssl then -- start ssl session self:starttls() else -- normal connection self:_start_session( self.listener.onconnect ) @@ -489,6 +489,7 @@ do _sslctx = sslctx; -- parameters _usingssl = false; -- client is using ssl; } + if not ssl then interface.starttls = false; end interface.id = tostring(interface):match("%x+$"); interface.writecallback = function( event ) -- called on write events --vdebug( "new client write event, id/ip/port:", interface, ip, port ) @@ -670,7 +671,7 @@ do interface._connections = interface._connections + 1 -- increase connection count local clientinterface = handleclient( client, ip, port, interface, pattern, listener, nil, sslctx ) --vdebug( "client id:", clientinterface, "startssl:", startssl ) - if sslctx then + if ssl and sslctx then clientinterface:starttls(sslctx) else clientinterface:_start_session( clientinterface.onconnect ) diff --git a/net/server_select.lua b/net/server_select.lua index db4475e2..685cd13e 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -55,8 +55,8 @@ local coroutine_yield = coroutine.yield --// extern libs //-- -local luasec = select( 2, pcall( require, "ssl" ) ) -local luasocket = require "socket" +local luasec = use "ssl" +local luasocket = use "socket" or require "socket" --// extern lib methods //-- @@ -472,7 +472,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport _sendlistlen = removesocket( _sendlist, socket, _sendlistlen ) -- delete socket from writelist _ = needtls and handler:starttls(nil, true) _writetimes[ handler ] = nil - _ = toclose and handler.close( ) + _ = toclose and handler.close( ) return true elseif byte and ( err == "timeout" or err == "wantwrite" ) then -- want write buffer = string_sub( buffer, byte + 1, bufferlen ) -- new buffer @@ -601,8 +601,10 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport handler.readbuffer = _readbuffer handler.sendbuffer = _sendbuffer end + else + handler.readbuffer = _readbuffer + handler.sendbuffer = _sendbuffer end - send = socket.send receive = socket.receive shutdown = ( ssl and id ) or socket.shutdown |