Commit bdc45e39 authored by Gei0r's avatar Gei0r Committed by Me No Dev

[OTA] Fix "Error response from device" if OK response comes to early (#1695)

Because TCP is stream-based, an earlier read can 'take away' the "OK" response
from the device, so that a later read doesn't get the message.
parent a7ddf395
...@@ -179,6 +179,7 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm ...@@ -179,6 +179,7 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm
try: try:
connection.sendall(chunk) connection.sendall(chunk)
res = connection.recv(10) res = connection.recv(10)
lastResponseContainedOK = 'OK' in res.decode()
except: except:
sys.stderr.write('\n') sys.stderr.write('\n')
logging.error('Error Uploading') logging.error('Error Uploading')
...@@ -187,6 +188,13 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm ...@@ -187,6 +188,13 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm
sock.close() sock.close()
return 1 return 1
if lastResponseContainedOK:
logging.info('Success')
connection.close()
f.close()
sock.close()
return 0
sys.stderr.write('\n') sys.stderr.write('\n')
logging.info('Waiting for result...') logging.info('Waiting for result...')
try: try:
......
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