MCPcopy Index your code
hub / github.com/pyload/pyload / ServerSocket

Class ServerSocket

module/remote/thriftbackend/Socket.py:95–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93
94
95class ServerSocket(TServerSocket, Socket):
96 def __init__(self, port=7228, host="0.0.0.0", key="", cert=""):
97 self.host = host
98 self.port = port
99 self.key = key
100 self.cert = cert
101 self.handle = None
102
103 def listen(self):
104 if self.cert and self.key:
105 SSL = __import__("OpenSSL", globals(), locals(), "SSL", -1).SSL
106 WantReadError = SSL.WantReadError
107 ctx = SSL.Context(SSL.SSLv23_METHOD)
108 ctx.use_privatekey_file(self.key)
109 ctx.use_certificate_file(self.cert)
110
111 tmpConnection = SSL.Connection(ctx, socket.socket(socket.AF_INET, socket.SOCK_STREAM))
112 tmpConnection.set_accept_state()
113 self.handle = SecureSocketConnection(tmpConnection)
114
115 else:
116 self.handle = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
117
118
119 self.handle.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
120 if hasattr(self.handle, 'set_timeout'):
121 self.handle.set_timeout(None)
122 self.handle.bind((self.host, self.port))
123 self.handle.listen(128)
124
125 def accept(self):
126 client, addr = self.handle.accept()
127 result = Socket()
128 result.setHandle(client)
129 return result

Callers 1

setupMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected