aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/dns.lua11
-rw-r--r--net/server_event.lua7
-rw-r--r--net/server_select.lua10
3 files changed, 16 insertions, 12 deletions
diff --git a/net/dns.lua b/net/dns.lua
index 10ac50a4..ca5f3c62 100644
--- a/net/dns.lua
+++ b/net/dns.lua
@@ -594,17 +594,18 @@ end
function resolver:remember(rr, type) -- - - - - - - - - - - - - - remember
--print ('remember', type, rr.class, rr.type, rr.name)
+ local qname, qtype, qclass = standardize(rr.name, rr.type, rr.class);
if type ~= '*' then
- type = rr.type;
- local all = get(self.cache, rr.class, '*', rr.name);
+ type = qtype;
+ local all = get(self.cache, qclass, '*', qname);
--print('remember all', all);
if all then append(all, rr); end
end
self.cache = self.cache or setmetatable({}, cache_metatable);
- local rrs = get(self.cache, rr.class, type, rr.name) or
- set(self.cache, rr.class, type, rr.name, setmetatable({}, rrs_metatable));
+ local rrs = get(self.cache, qclass, type, qname) or
+ set(self.cache, qclass, type, qname, setmetatable({}, rrs_metatable));
append(rrs, rr);
if type == 'MX' then self.unsorted[rrs] = true; end
@@ -723,7 +724,7 @@ function resolver:receive(rset) -- - - - - - - - - - - - - - - - - receive
for i,sock in pairs(rset) do
if self.socketset[sock] then
- local packet = sock.receive();
+ local packet = sock:receive();
if packet then
response = self:decode(packet);
if response and self.active[response.header.id]
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