From 8ac915e75fcabb3a934e40ccdcb468716fb3d6b8 Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Wed, 28 Feb 2018 17:17:02 +0100 Subject: [PATCH] src/trezor/wire: make sure the writes succeed --- src/trezor/wire/codec_v1.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/trezor/wire/codec_v1.py b/src/trezor/wire/codec_v1.py index 25c9bb9940..ec106f4cc9 100644 --- a/src/trezor/wire/codec_v1.py +++ b/src/trezor/wire/codec_v1.py @@ -1,7 +1,7 @@ from micropython import const import ustruct -from trezor import io +from trezor import io, ui from trezor import loop from trezor import utils @@ -134,8 +134,11 @@ class Writer: if self.ofs == _REP_LEN: # we are at the end of the report, flush it - await write - self.iface.write(self.data) + while True: + await write + n = self.iface.write(self.data) + if n == len(self.data): + break self.ofs = _REP_CONT_DATA return nwritten @@ -149,5 +152,9 @@ class Writer: self.data[self.ofs] = 0x00 self.ofs += 1 - await loop.select(self.iface.iface_num() | io.POLL_WRITE) - self.iface.write(self.data) + write = loop.select(self.iface.iface_num() | io.POLL_WRITE) + while True: + await write + n = self.iface.write(self.data) + if n == len(self.data): + break