From b6f90db3e637bbc2f531677fdff8acf7e5a9b0d6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 24 Jun 2011 10:49:32 -0600 Subject: [PATCH] ... --- src/calibre/utils/ipc/proxy.py | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/calibre/utils/ipc/proxy.py diff --git a/src/calibre/utils/ipc/proxy.py b/src/calibre/utils/ipc/proxy.py new file mode 100644 index 0000000000..b60f9eb755 --- /dev/null +++ b/src/calibre/utils/ipc/proxy.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import (unicode_literals, division, absolute_import, + print_function) + +__license__ = 'GPL v3' +__copyright__ = '2011, Kovid Goyal ' +__docformat__ = 'restructuredtext en' + +import os +from threading import Thread +from multiprocessing.connection import arbitrary_address, Listener + +from calibre.constants import iswindows + +class Server(Thread): + + def __init__(self): + Thread.__init__(self) + self.daemon = True + + self.auth_key = os.urandom(32) + self.address = arbitrary_address('AF_PIPE' if iswindows else 'AF_UNIX') + if iswindows and self.address[1] == ':': + self.address = self.address[2:] + self.listener = Listener(address=self.address, + authkey=self.auth_key, backlog=4) + + self.keep_going = True + + def stop(self): + self.keep_going = False + try: + self.listener.close() + except: + pass + + def run(self): + while self.keep_going: + try: + conn = self.listener.accept() + self.handle_client(conn) + except: + pass + +