From 83a49dcd4e150fc8cdb26c92a6b1c353d00f13aa Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 17 Jul 2007 22:30:23 -0400 Subject: [PATCH] Don't close GlibTCPServer sockets prematurely --- NEWS | 2 ++ sugar/network.py | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 6095c577..41ec296e 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +* Don't close GlibTCPServer sockets prematurely (dcbw) + Snapshot 5212790236 * Fix initialization order of buddy class '_activities' member (dcbw) diff --git a/sugar/network.py b/sugar/network.py index 47927771..5579aa9b 100644 --- a/sugar/network.py +++ b/sugar/network.py @@ -69,6 +69,11 @@ class GlibTCPServer(SocketServer.TCPServer): self.handle_request() return True + def close_request(self, request): + """Called to clean up an individual request.""" + # let the request be closed by the request handler when its done + pass + class ChunkedGlibHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): """RequestHandler class that integrates with Glib mainloop. It writes @@ -112,6 +117,7 @@ class ChunkedGlibHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def _cleanup(self): if self._file: self._file.close() + self._file = None if self._srcid > 0: gobject.source_remove(self._srcid) self._srcid = 0 @@ -507,12 +513,23 @@ def xmlrpc_test(loop): error_handler=xmlrpc_error_cb, user_data=loop) -def main(): - loop = gobject.MainLoop() +def start_xmlrpc(): server = GlibXMLRPCServer(("", 8888)) inst = Test() server.register_instance(inst) gobject.idle_add(xmlrpc_test, loop) + +class TestReqHandler(ChunkedGlibHTTPRequestHandler): + def translate_path(self, path): + return "/tmp/foo" + +def start_http(): + server = GlibTCPServer(("", 8890), TestReqHandler) + +def main(): + loop = gobject.MainLoop() +# start_xmlrpc() + start_http() try: loop.run() except KeyboardInterrupt: @@ -521,3 +538,5 @@ def main(): if __name__ == "__main__": main() + +