xpra icon
Bug tracker and wiki

Ticket #1211: websockify-win32.patch

File websockify-win32.patch, 3.8 KB (added by Antoine Martin, 4 years ago)

allow websockify to run on win32

  • websockify/websocket.py

    diff --git a/websockify/websocket.py b/websockify/websocket.py
    index ffa9b90..3c203f7 100644
    a b except: 
    5050        return struct.unpack(fmt, slice)
    5151
    5252# Degraded functionality if these imports are missing
    53 for mod, msg in [('numpy', 'HyBi protocol will be slower'),
    54                  ('ssl', 'TLS/SSL/wss is disabled'),
    55                  ('multiprocessing', 'Multi-Processing is disabled'),
    56                  ('resource', 'daemonizing is disabled')]:
     53OPTIONAL_FEATURES = [
     54                     ('numpy', 'HyBi protocol will be slower'),
     55                     ('ssl', 'TLS/SSL/wss is disabled'),
     56                     ('multiprocessing', 'Multi-Processing is disabled'),
     57                    ]
     58if not sys.platform.startswith("win"):
     59    #resource module is not available on Windows
     60    OPTIONAL_FEATURES.append(('resource', 'daemonizing is disabled'))
     61for mod, msg in OPTIONAL_FEATURES:
    5762    try:
    5863        globals()[mod] = __import__(mod)
    5964    except ImportError:
    class WebSocketRequestHandler(SimpleHTTPRequestHandler): 
    550555            else:
    551556                SimpleHTTPRequestHandler.do_GET(self)
    552557
     558    def copyfile(self, source, outputfile):
     559        """Adds retry code for WSAEWOULDBLOCK on MS Windows"""
     560        if not sys.platform.startswith("win"):
     561            return SimpleHTTPRequestHandler.copyfile(self, source, outputfile)
     562        import shutil
     563        while True:
     564            try:
     565                shutil.copyfileobj(source, outputfile)
     566                return
     567            except (IOError, OSError) as e:
     568                if e[0]==errno.WSAEWOULDBLOCK:
     569                    continue
     570                raise
     571
    553572    def list_directory(self, path):
    554573        if self.file_only:
    555574            self.send_error(404, "No such file")
    class WebSocketServer(object): 
    9871006        original_signals = {
    9881007            signal.SIGINT: signal.getsignal(signal.SIGINT),
    9891008            signal.SIGTERM: signal.getsignal(signal.SIGTERM),
    990             signal.SIGCHLD: signal.getsignal(signal.SIGCHLD),
    9911009        }
    9921010        signal.signal(signal.SIGINT, self.do_SIGINT)
    9931011        signal.signal(signal.SIGTERM, self.do_SIGTERM)
    994         if not multiprocessing:
    995             # os.fork() (python 2.4) child reaper
    996             signal.signal(signal.SIGCHLD, self.fallback_SIGCHLD)
    997         else:
    998             # make sure that _cleanup is called when children die
    999             # by calling active_children on SIGCHLD
    1000             signal.signal(signal.SIGCHLD, self.multiprocessing_SIGCHLD)
     1012        #SIGCHLD is only available on posix:
     1013        SIGCHLD = getattr(signal, "SIGCHLD", None)
     1014        if SIGCHLD:
     1015            original_signals[SIGCHLD] = signal.getsignal(SIGCHLD)
     1016            if not multiprocessing:
     1017                # os.fork() (python 2.4) child reaper
     1018                signal.signal(SIGCHLD, self.fallback_SIGCHLD)
     1019            else:
     1020                # make sure that _cleanup is called when children die
     1021                # by calling active_children on SIGCHLD
     1022                signal.signal(SIGCHLD, self.multiprocessing_SIGCHLD)
    10011023
    10021024        last_active_time = self.launch_time
    10031025        try:
  • websockify/websocketproxy.py

    diff --git a/websockify/websocketproxy.py b/websockify/websocketproxy.py
    index 837d801..61c34c2 100755
    a b class WebSocketProxy(websocket.WebSocketServer): 
    229229
    230230    def __init__(self, RequestHandlerClass=ProxyRequestHandler, *args, **kwargs):
    231231        # Save off proxy specific options
     232        if sys.platform.startswith("win"):
     233            kwargs.pop("multiprocessing_fork", None)
    232234        self.target_host    = kwargs.pop('target_host', None)
    233235        self.target_port    = kwargs.pop('target_port', None)
    234236        self.wrap_cmd       = kwargs.pop('wrap_cmd', None)