You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
Python
48 lines
1.1 KiB
Python
#!/usr/bin/python
|
|
|
|
################################
|
|
# Configuration starts here
|
|
|
|
allowed_certs = '/home/sven/ssl/allowed'
|
|
|
|
# Configuration ends here
|
|
################################
|
|
|
|
import socket, ssl, time, math
|
|
from shared.core import *
|
|
|
|
select_inputs = []
|
|
select_outputs = []
|
|
client_map = {}
|
|
|
|
client = SSLClient("localhost", 9151, allowed_certs)
|
|
select_inputs.append(client.ssl_sock)
|
|
select_outputs.append(client.ssl_sock)
|
|
client_map[client.ssl_sock.fileno()] = client.client
|
|
|
|
while True:
|
|
readable, writable, error = select.select(select_inputs, select_outputs, select_inputs)
|
|
|
|
if len(readable) > 0:
|
|
for sock in readable:
|
|
try:
|
|
data = sock.recv(1024)
|
|
cur_client = client_map[sock.fileno()]
|
|
|
|
if data:
|
|
cur_client.process_data(data)
|
|
else:
|
|
cur_client.end()
|
|
select_inputs = remove_from_list(select_inputs, sock)
|
|
print "NOTICE: Client disconnected"
|
|
except ssl.SSLError, err:
|
|
if err.args[0] == ssl.SSL_ERROR_WANT_READ:
|
|
select.select([sock], [], [])
|
|
elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
|
|
select.select([], [sock], [])
|
|
else:
|
|
raise
|
|
else:
|
|
time.sleep(0.010)
|
|
|