Skip to content

Commit

Permalink
I think this is way less hacky
Browse files Browse the repository at this point in the history
  • Loading branch information
dmcdo committed Jan 10, 2023
1 parent 106c798 commit 20011a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/containers/container_manager_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ def _send_select(self) -> None:
try:
while not self.recv_closed:
if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
self.sock.send(bytes(sys.stdin.readline(), "utf-8"))
buffer = bytes(sys.stdin.readline(), "utf-8")
while buffer:
msg = buffer[:255]
self.sock.send(bytes([len(msg)]) + msg)
buffer = buffer[255:]
else:
self.sock.send(b"\x00")
time.sleep(0.1)
Expand All @@ -309,7 +313,11 @@ def _send_msvcrt(self) -> None:

if char == "\r":
print(end="\n")
self.sock.send(bytes(msg + "\n", "utf-8"))
buffer = bytes(msg + "\n", "utf-8")
while buffer:
msg = buffer[:255]
self.sock.send(bytes([len(msg)]) + msg)
buffer = buffer[255:]
msg = ""

elif char == "\b":
Expand Down
7 changes: 5 additions & 2 deletions src/containers/container_manager_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,11 @@ def send_and_recv(self):

def _recv(self):
try:
while msg := self.client_sock.recv(1024):
self.stdin.write(bytes(filter(lambda b: b, msg)))
while msg := self.client_sock.recv(1 << 16):
while msg:
size = msg[0]
self.stdin.write(msg[1:size + 1])
msg = msg[size + 1:]
except (ConnectionError, OSError):
pass

Expand Down

0 comments on commit 20011a4

Please sign in to comment.