diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-04-29 01:05:02 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-04-29 01:05:02 +0300 |
commit | f41e1f1bb7c91f12a48cf0480ede94d7255d1605 (patch) | |
tree | 8a935aaa6ef4247e57b483894e3a991919969e17 /extmod/modwebrepl.c | |
parent | 6514ff61609d414ddef43072020508aa3bab770d (diff) |
extmod/modwebrepl: Keep reading data when there's something to read.
EAGAIN should be returned only if underlying socket returned it. Wrap
existing read function into external loop to process all data available.
Diffstat (limited to 'extmod/modwebrepl.c')
-rw-r--r-- | extmod/modwebrepl.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/extmod/modwebrepl.c b/extmod/modwebrepl.c index 43b67b048..f6a5ed0eb 100644 --- a/extmod/modwebrepl.c +++ b/extmod/modwebrepl.c @@ -144,7 +144,17 @@ STATIC void handle_op(mp_obj_webrepl_t *self) { } } +STATIC mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode); + STATIC mp_uint_t webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { + mp_uint_t out_sz; + do { + out_sz = _webrepl_read(self_in, buf, size, errcode); + } while (out_sz == -2); + return out_sz; +} + +STATIC mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { // We know that os.dupterm always calls with size = 1 assert(size == 1); mp_obj_webrepl_t *self = self_in; @@ -171,8 +181,7 @@ STATIC mp_uint_t webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int * } self->hdr_to_recv -= hdr_sz; if (self->hdr_to_recv != 0) { - *errcode = EAGAIN; - return MP_STREAM_ERROR; + return -2; } } @@ -180,8 +189,7 @@ STATIC mp_uint_t webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int * handle_op(self); - *errcode = EAGAIN; - return MP_STREAM_ERROR; + return -2; } if (self->data_to_recv != 0) { @@ -213,8 +221,7 @@ STATIC mp_uint_t webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int * } } - *errcode = EAGAIN; - return MP_STREAM_ERROR; + return -2; } STATIC mp_uint_t webrepl_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { |