Commit 05c0e693 authored by ibuler's avatar ibuler

remove select from interacitve

parent 6a623a6d
...@@ -41,6 +41,7 @@ class Coco: ...@@ -41,6 +41,7 @@ class Coco:
self.ws = None self.ws = None
self.root_path = root_path self.root_path = root_path
self.name = name self.name = name
self.lock = threading.Lock()
if name is None: if name is None:
self.name = self.config['NAME'] self.name = self.config['NAME']
...@@ -97,14 +98,20 @@ class Coco: ...@@ -97,14 +98,20 @@ class Coco:
self.sshd.shutdown() self.sshd.shutdown()
def add_client(self, client): def add_client(self, client):
with self.lock:
self.clients.append(client) self.clients.append(client)
print("%s add client, now %d s" % (self.name, len(self.clients))) print("%s add client, now %d s" % (self.name, len(self.clients)))
def remove_client(self, client): def remove_client(self, client):
with self.lock:
self.clients.remove(client) self.clients.remove(client)
print("%s remove client, now %d s" % (self.name, len(self.clients)))
try:
client.send("Closed by server") client.send("Closed by server")
client.close() client.close()
print("%s remove client, now %d s" % (self.name, len(self.clients))) except:
pass
def monitor_session(self): def monitor_session(self):
pass pass
......
...@@ -44,11 +44,10 @@ class InteractiveServer: ...@@ -44,11 +44,10 @@ class InteractiveServer:
self.request.meta.get("height", 24)) self.request.meta.get("height", 24))
self.client.send(wr(prompt, before=1, after=0)) self.client.send(wr(prompt, before=1, after=0))
while True: while True:
r, w, x = select.select([self.client], [], [])
if self.client in r:
data = self.client.recv(10) data = self.client.recv(10)
if len(data) == 0: if len(data) == 0:
self.app.remove_client(self.client) self.app.remove_client(self.client)
break
# Client input backspace # Client input backspace
if data in char.BACKSPACE_CHAR: if data in char.BACKSPACE_CHAR:
# If input words less than 0, should send 'BELL' # If input words less than 0, should send 'BELL'
...@@ -82,7 +81,6 @@ class InteractiveServer: ...@@ -82,7 +81,6 @@ class InteractiveServer:
input_data.append(data) input_data.append(data)
def dispatch(self, opt): def dispatch(self, opt):
print(opt)
if opt in ['q', 'Q']: if opt in ['q', 'Q']:
self.app.remove_client(self.client) self.app.remove_client(self.client)
return return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment