diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-05-07 01:48:12 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-05-07 02:17:14 +0300 |
commit | 6e73143de894126c7b453dbe3185b9f1b39d487b (patch) | |
tree | f07712c19cd572a4342b812701417a844e338536 /py | |
parent | a592104acdc56fa6511311ecfe6d4de63415d5ab (diff) | |
download | micropython-6e73143de894126c7b453dbe3185b9f1b39d487b.tar.gz micropython-6e73143de894126c7b453dbe3185b9f1b39d487b.zip |
stream: Add compliant handling of non-blocking readall().
Diffstat (limited to 'py')
-rw-r--r-- | py/stream.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/py/stream.c b/py/stream.c index 486ad4bb1d..d3ec8e298d 100644 --- a/py/stream.c +++ b/py/stream.c @@ -119,6 +119,15 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in) { while (true) { machine_int_t out_sz = o->type->stream_p->read(self_in, p, current_read, &error); if (out_sz == -1) { + if (is_nonblocking_error(error)) { + // With non-blocking streams, we read as much as we can. + // If we read nothing, return None, just like read(). + // Otherwise, return data read so far. + if (total_size == 0) { + return mp_const_none; + } + break; + } nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", error)); } if (out_sz == 0) { |