summaryrefslogtreecommitdiffstatshomepage
path: root/py/modio.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/modio.c')
-rw-r--r--py/modio.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/py/modio.c b/py/modio.c
index 423315081f..2fbe6bc1e1 100644
--- a/py/modio.c
+++ b/py/modio.c
@@ -78,10 +78,13 @@ STATIC mp_uint_t bufwriter_write(mp_obj_t self_in, const void *buf, mp_uint_t si
memcpy(self->buf + self->len, buf, rem);
buf = (byte*)buf + rem;
size -= rem;
- mp_uint_t out_sz = mp_stream_writeall(self->stream, self->buf, self->alloc, errcode);
- if (out_sz == MP_STREAM_ERROR) {
+ mp_uint_t out_sz = mp_stream_write_exactly(self->stream, self->buf, self->alloc, errcode);
+ if (*errcode != 0) {
return MP_STREAM_ERROR;
}
+ // TODO: try to recover from a case of non-blocking stream, e.g. move
+ // remaining chunk to the beginning of buffer.
+ assert(out_sz == self->alloc);
self->len = 0;
}
@@ -93,9 +96,12 @@ STATIC mp_obj_t bufwriter_flush(mp_obj_t self_in) {
if (self->len != 0) {
int err;
- mp_uint_t out_sz = mp_stream_writeall(self->stream, self->buf, self->len, &err);
+ mp_uint_t out_sz = mp_stream_write_exactly(self->stream, self->buf, self->len, &err);
+ // TODO: try to recover from a case of non-blocking stream, e.g. move
+ // remaining chunk to the beginning of buffer.
+ assert(out_sz == self->len);
self->len = 0;
- if (out_sz == MP_STREAM_ERROR) {
+ if (err != 0) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(err)));
}
}