From 2c0e8cb8f474360ce36624c1499a480fea376654 Mon Sep 17 00:00:00 2001 From: Michal Srb Date: Tue, 1 Aug 2017 15:35:34 +0200 Subject: [PATCH] Fix inetd mode on Python 2. In python 2 the ssl.wrap_socket doesn't work on sockets created using socket.fromfd. The workaround is to wrap the socket returned by socket.fromfd into another socket object using the private _sock constructor parameter. --- websockify/websockifyserver.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/websockify/websockifyserver.py b/websockify/websockifyserver.py index b2be9dc..0d16540 100644 --- a/websockify/websockifyserver.py +++ b/websockify/websockifyserver.py @@ -676,6 +676,10 @@ class WebSockifyServer(object): if self.listen_fd != None: lsock = socket.fromfd(self.listen_fd, socket.AF_INET, socket.SOCK_STREAM) + if sys.hexversion < 0x3000000: + # For python 2 we have to wrap the "raw" socket into a socket object, + # otherwise ssl wrap_socket doesn't work. + lsock = socket.socket(_sock=lsock) else: lsock = self.socket(self.listen_host, self.listen_port, False, self.prefer_ipv6,