From: Ben Darnell Date: Tue, 15 Feb 2011 04:10:27 +0000 (-0800) Subject: Detect the connection being closed by the server in SimpleAsyncHTTPClient. X-Git-Tag: v1.2.0~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4191ed34f02039d556e279da8b8b7742b4bf1df0;p=thirdparty%2Ftornado.git Detect the connection being closed by the server in SimpleAsyncHTTPClient. --- diff --git a/tornado/simple_httpclient.py b/tornado/simple_httpclient.py index a19805d8b..f550980bb 100644 --- a/tornado/simple_httpclient.py +++ b/tornado/simple_httpclient.py @@ -162,16 +162,17 @@ class _HTTPConnection(object): self._connect_timeout = self.io_loop.add_timeout( self.start_time + timeout, self._on_timeout) + self.stream.set_close_callback(self._on_close) self.stream.connect((host, port), functools.partial(self._on_connect, parsed)) def _on_timeout(self): self._timeout = None - self.stream.close() if self.callback is not None: self.callback(HTTPResponse(self.request, 599, error=HTTPError(599, "Timeout"))) self.callback = None + self.stream.close() def _on_connect(self, parsed): if self._timeout is not None: @@ -229,6 +230,13 @@ class _HTTPConnection(object): self.callback(HTTPResponse(self.request, 599, error=e)) self.callback = None + def _on_close(self): + if self.callback is not None: + self.callback(HTTPResponse(self.request, 599, + error=HTTPError(599, + "Connection closed"))) + self.callback = None + def _on_headers(self, data): first_line, _, header_data = data.partition("\r\n") match = re.match("HTTP/1.[01] ([0-9]+) .*", first_line)