Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flow of ACKs to ensure we do not hang on final buf write #155

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions rshell/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,8 +1093,6 @@ def recv_file_from_host(src_file, dst_filename, filesize, dst_mode='wb'):
write_buf = bytearray(buf_size)
read_buf = bytearray(buf_size)
while bytes_remaining > 0:
# Send back an ack as a form of flow control
sys.stdout.write('\x06')
read_size = min(bytes_remaining, buf_size)
buf_remaining = read_size
buf_index = 0
Expand All @@ -1116,6 +1114,10 @@ def recv_file_from_host(src_file, dst_filename, filesize, dst_mode='wb'):
if hasattr(os, 'sync'):
os.sync()
bytes_remaining -= read_size

# Send back an ack as a form of flow control
sys.stdout.write('\x06')

return True
except:
return False
Expand All @@ -1129,12 +1131,6 @@ def send_file_to_remote(dev, src_file, dst_filename, filesize, dst_mode='wb'):
save_timeout = dev.timeout
dev.timeout = 2
while bytes_remaining > 0:
# Wait for ack so we don't get too far ahead of the remote
ack = dev.read(1)
if ack is None or ack != b'\x06':
sys.stderr.write("timed out or error in transfer to remote: {!r}\n".format(ack))
sys.exit(2)

if HAS_BUFFER:
buf_size = BUFFER_SIZE
else:
Expand All @@ -1147,6 +1143,13 @@ def send_file_to_remote(dev, src_file, dst_filename, filesize, dst_mode='wb'):
dev.write(buf)
else:
dev.write(binascii.hexlify(buf))

# Wait for ack so we don't get too far ahead of the remote
ack = dev.read(1)
if ack is None or ack != b'\x06':
sys.stderr.write("timed out or error in transfer to remote: {!r}\n".format(ack))
sys.exit(2)

bytes_remaining -= read_size
#sys.stdout.write('\r')
dev.timeout = save_timeout
Expand Down