Changeset

2677:467568f1117d

Merge with 0.7
author Matthew Wild <mwild1@gmail.com>
date Fri, 19 Feb 2010 03:31:15 +0000
parents 2670:35f36a53c671 (current diff) 2676:4516888fc42d (diff)
children 2678:c5882e2e12b5
files
diffstat 3 files changed, 17 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/core/s2smanager.lua	Fri Feb 19 02:59:00 2010 +0000
+++ b/core/s2smanager.lua	Fri Feb 19 03:31:15 2010 +0000
@@ -301,7 +301,7 @@
 end
 
 function make_connect(host_session, connect_host, connect_port)
-	host_session.log("info", "Beginning new connection attempt to %s (%s:%d)", host_session.to_host, connect_host, connect_port);
+	(host_session.log or log)("info", "Beginning new connection attempt to %s (%s:%d)", host_session.to_host, connect_host, connect_port);
 	-- Ok, we're going to try to connect
 	
 	local from_host, to_host = host_session.from_host, host_session.to_host;
--- a/net/http.lua	Fri Feb 19 02:59:00 2010 +0000
+++ b/net/http.lua	Fri Feb 19 03:31:15 2010 +0000
@@ -17,11 +17,10 @@
 local listener = connlisteners_get("httpclient") or error("No httpclient listener!");
 
 local t_insert, t_concat = table.insert, table.concat;
-local tonumber, tostring, pairs, xpcall, select, debug_traceback, char, format = 
+local tonumber, tostring, pairs, xpcall, select, debug_traceback, char, format =
         tonumber, tostring, pairs, xpcall, select, debug.traceback, string.char, string.format;
 
 local log = require "util.logger".init("http");
-local print = function () end
 
 module "http"
 
@@ -43,6 +42,7 @@
 		elseif request.state ~= "completed" then
 			-- Error.. connection was closed prematurely
 			request.callback("connection-closed", 0, request);
+			return;
 		end
 		destroy_request(request);
 		request.body = nil;
@@ -50,7 +50,7 @@
 		return;
 	end
 	if request.state == "body" and request.state ~= "completed" then
-		print("Reading body...")
+		log("debug", "Reading body...")
 		if not request.body then request.body = {}; request.havebodylength, request.bodylength = 0, tonumber(request.responseheaders["content-length"]); end
 		if startpos then
 			data = data:sub(startpos, -1)
@@ -67,11 +67,11 @@
 				request.body = nil;
 				request.state = "completed";
 			else
-				print("", "Have "..request.havebodylength.." bytes out of "..request.bodylength);
+				log("debug", "Have "..request.havebodylength.." bytes out of "..request.bodylength);
 			end
 		end
 	elseif request.state == "headers" then
-		print("Reading headers...")
+		log("debug", "Reading headers...")
 		local pos = startpos;
 		local headers, headers_complete = request.responseheaders;
 		if not headers then
@@ -83,12 +83,12 @@
 			local k, v = line:match("(%S+): (.+)");
 			if k and v then
 				headers[k:lower()] = v;
-				--print("Header: "..k:lower().." = "..v);
+				--log("debug", "Header: "..k:lower().." = "..v);
 			elseif #line == 0 then
 				headers_complete = true;
 				break;
 			else
-				print("Unhandled header line: "..line);
+				log("warn", "Unhandled header line: "..line);
 			end
 		end
 		if not headers_complete then return; end
@@ -102,11 +102,14 @@
 			return request_reader(request, data, startpos);
 		end
 	elseif request.state == "status" then
-		print("Reading status...")
+		log("debug", "Reading status...")
 		local http, code, text, linelen = data:match("^HTTP/(%S+) (%d+) (.-)\r\n()", startpos);
 		code = tonumber(code);
 		if not code then
-			return request.callback("invalid-status-line", 0, request);
+			log("warn", "Invalid HTTP status line, telling callback then closing");
+			local ret = request.callback("invalid-status-line", 0, request);
+			destroy_request(request);
+			return ret;
 		end
 		
 		request.code, request.responseversion = code, http;
@@ -208,8 +211,9 @@
 
 function destroy_request(request)
 	if request.conn then
-		request.handler.close()
-		listener.ondisconnect(request.conn, "closed");
+		request.conn = nil;
+		request.handler:close()
+		listener.ondisconnect(request.handler, "closed");
 	end
 end
 
--- a/net/httpclient_listener.lua	Fri Feb 19 02:59:00 2010 +0000
+++ b/net/httpclient_listener.lua	Fri Feb 19 03:31:15 2010 +0000
@@ -30,7 +30,7 @@
 
 function httpclient.ondisconnect(conn, err)
 	local request = requests[conn];
-	if request then
+	if request and err ~= "closed" then
 		request:reader(nil);
 	end
 	requests[conn] = nil;