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.
This commit is contained in:
Michal Srb 2017-08-01 15:35:34 +02:00
parent 867cb21ba0
commit 2c0e8cb8f4
1 changed files with 4 additions and 0 deletions

View File

@ -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,