From f1871510b798f5dbe8fa6263fe2e9478c1cdac6d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 1 Mar 2010 16:45:13 +0000 Subject: net.server_event: Improve and fix potential traceback in logging of new incoming connections --- net/server_event.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'net') diff --git a/net/server_event.lua b/net/server_event.lua index d041ae43..70435f38 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -671,16 +671,16 @@ do debug( "maximal connections reached, refuse client connection; accept delay:", delay ) return EV_TIMEOUT, delay -- delay for next accept attemp end - local ip, port = client:getpeername( ) + local client_ip, client_port = client:getpeername( ) interface._connections = interface._connections + 1 -- increase connection count - local clientinterface = handleclient( client, ip, port, interface, pattern, listener, nil, sslctx ) + local clientinterface = handleclient( client, client_ip, client_port, interface, pattern, listener, nil, sslctx ) --vdebug( "client id:", clientinterface, "startssl:", startssl ) if ssl and sslctx then clientinterface:starttls(sslctx) else clientinterface:_start_session( clientinterface.onconnect ) end - debug( "accepted incoming client connection from:", ip, port ) + debug( "accepted incoming client connection from:", client_ip or "", client_port or "", "to", port or ""); client, err = server:accept() -- try to accept again end -- cgit v1.2.3 From 9d6219b596ccf58fc409a7a84b6063b1c2955222 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 1 Mar 2010 18:06:54 +0000 Subject: net.server_select: Fix calling method of some handler.close()s --- net/server_select.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'net') diff --git a/net/server_select.lua b/net/server_select.lua index 685cd13e..ca8b1113 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -435,7 +435,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport local len = string_len( buffer ) if len > maxreadlen then disconnect( handler, "receive buffer exceeded" ) - handler.close( true ) + handler:close( true ) return false end local count = len * STAT_UNIT @@ -448,7 +448,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport out_put( "server.lua: client ", tostring(ip), ":", tostring(clientport), " read error: ", tostring(err) ) fatalerror = true disconnect( handler, err ) - _ = handler and handler.close( ) + _ = handler and handler:close( ) return false end end @@ -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 handlerclose( ) return true elseif byte and ( err == "timeout" or err == "wantwrite" ) then -- want write buffer = string_sub( buffer, byte + 1, bufferlen ) -- new buffer @@ -485,7 +485,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport out_put( "server.lua: client ", tostring(ip), ":", tostring(clientport), " write error: ", tostring(err) ) fatalerror = true disconnect( handler, err ) - _ = handler and handler.close( ) + _ = handler and handler:close( ) return false end end -- cgit v1.2.3 From 52817c55177ca4ad795705a89d1d8a1a40e9688b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 1 Mar 2010 18:46:37 +0000 Subject: net.server_event: Fix some global accesses --- net/server_event.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'net') diff --git a/net/server_event.lua b/net/server_event.lua index 70435f38..b767cb20 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -543,7 +543,7 @@ do local callback = function( ) interface:_close() interface.eventwritetimeout = nil - return evreturn, evtimeout + return -1; end interface.eventwritetimeout = addevent( base, nil, EV_TIMEOUT, callback, cfg.WRITE_TIMEOUT ) -- reg a new timeout event debug( "wantread during write attemp, reg it in readcallback but dont know what really happens next..." ) @@ -762,7 +762,7 @@ do local server = function( ) return nil, "this is a dummy server interface" end - local interface = wrapclient( client, ip, serverport, listeners, pattern, sslctx, startssl ) + local interface = wrapclient( client, ip, serverport, listener, pattern, sslctx, startssl ) interface:_start_connection( startssl ) debug( "new connection id:", interface.id ) return interface, err -- cgit v1.2.3 From 70e49af539d114e02baa8c7105d83e2728af18da Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 1 Mar 2010 18:47:03 +0000 Subject: net.server_select: Fix typo --- net/server_select.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'net') diff --git a/net/server_select.lua b/net/server_select.lua index ca8b1113..c4a1f19a 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -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 handlerclose( ) + _ = 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 -- cgit v1.2.3 From c071b4638d4a78d9c7e76ae973553e04cb5e22b6 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 5 Mar 2010 16:45:46 +0000 Subject: net.server_select: Fix for traceback when a read returns an error and no data (thanks dersd) --- net/server_select.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'net') diff --git a/net/server_select.lua b/net/server_select.lua index c4a1f19a..49cbe25d 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -430,7 +430,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport end local _readbuffer = function( ) -- this function reads data local buffer, err, part = receive( socket, pattern ) -- receive buffer with "pattern" - if not err or (err == "wantread" or err == "timeout") or string_len(part) > 0 then -- received something + if not err or (err == "wantread" or err == "timeout") or (part and string_len(part) > 0) then -- received something local buffer = buffer or part or "" local len = string_len( buffer ) if len > maxreadlen then -- cgit v1.2.3 From 322f02b17fac1dc673a1250ddbc4a954dec98696 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 5 Mar 2010 18:15:08 +0000 Subject: net.dns: More reliable parsing of resolv.conf - allow multiple nameserver IPs on one line (thanks dersd) --- net/dns.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'net') diff --git a/net/dns.lua b/net/dns.lua index ca5f3c62..7d1cba8e 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -538,8 +538,13 @@ function resolver:adddefaultnameservers() -- - - - - adddefaultnameservers local resolv_conf = io.open("/etc/resolv.conf"); if resolv_conf then for line in resolv_conf:lines() do - local address = line:gsub("#.*$", ""):match('^%s*nameserver%s+(%d+%.%d+%.%d+%.%d+)%s*$'); - if address then self:addnameserver(address) end + line = line:gsub("#.*$", "") + :match('^%s*nameserver%s+(.*)%s*$'); + if line then + line:gsub("%f[%d.](%d+%.%d+%.%d+%.%d+)%f[^%d.]", function (address) + self:addnameserver(address) + end); + end end end if not self.server or #self.server == 0 then -- cgit v1.2.3 From a201db970b44ac05204b19aa1c3fa973ea6e2e2a Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 5 Mar 2010 18:33:28 +0000 Subject: net.dns: Trailing whitespace --- net/dns.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'net') diff --git a/net/dns.lua b/net/dns.lua index 7d1cba8e..8855cc61 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -532,7 +532,7 @@ function resolver:adddefaultnameservers() -- - - - - adddefaultnameservers if not self.server or #self.server == 0 then -- TODO log warning about no nameservers, adding opendns servers as fallback self:addnameserver("208.67.222.222"); - self:addnameserver("208.67.220.220") ; + self:addnameserver("208.67.220.220"); end else -- posix local resolv_conf = io.open("/etc/resolv.conf"); @@ -801,7 +801,7 @@ function resolver:feed(sock, packet) set(self.wanted, q.class, q.type, q.name, nil); end end - end + end return response; end -- cgit v1.2.3