I am writing a web server. Centos, interacts with multiple clients and uses the select model. After running for a period of time, the program suddenly gets stuck in select. It is clear that socket is in establish status, and there should be packets on it, but select does not return. Not sure if there is something wrong with the select mechanism or something else. Code:
ip="x.x.x.x"
port1 = 8322
server = socket.socket()
server.setblocking(False)
server.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
server.bind((ip,port1));
server.listen(10)
cli_socket = socket.socket()
cli_socket.setblocking(False)
host = "127.0.0.1"
port2 = 12355
cli_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
cli_socket.bind((host, port2))
cli_socket.listen(5)
inputs=[server,cli_socket,]
while True:
readable, writable, exceptional = select.select(inputs, outputs, inputs, 30)
for s in readable:
if s is server:
conn,address = server.accept()
rec_buf=conn.recv(1024)
//make some handle here, store this connection in global data
conn.setblocking(0)
conn.sendall("pass")
inputs.append(conn)
elif s is cli_socket:
cli_conn, addr = s.accept()
command = cli_conn.recv(1024)
ret=command.split(",")
if ret[0] == "OPEN":
total_key[ret[1]].conn_sock.sendall("open")
cli_conn.send("success")
cli_conn.close()
else:
rec_buf=s.recv(1024)
//make some handle here
s.sendall("ok")
for s in exceptional:
inputs.remove(s)
s.close()