diff --git a/py/mpconfig.h b/py/mpconfig.h index 48494a21ff..9acfc142f5 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -249,6 +249,11 @@ typedef double mp_float_t; #define MICROPY_PATH_MAX (512) #endif +// Whether POSIX-semantics non-blocking streams are supported +#ifndef MICROPY_STREAMS_NON_BLOCK +#define MICROPY_STREAMS_NON_BLOCK (0) +#endif + // Whether to use computed gotos in the VM, or a switch // Computed gotos are roughly 10% faster, and increase VM code size by a little #ifndef MICROPY_USE_COMPUTED_GOTO diff --git a/py/stream.c b/py/stream.c index 96bf94fcd9..9eb438b538 100644 --- a/py/stream.c +++ b/py/stream.c @@ -25,7 +25,6 @@ */ #include -#include #include "mpconfig.h" #include "nlr.h" @@ -33,6 +32,9 @@ #include "qstr.h" #include "obj.h" #include "stream.h" +#if MICROPY_STREAMS_NON_BLOCK +#include +#endif // This file defines generic Python stream read/write methods which // dispatch to the underlying stream interface of an object. @@ -42,9 +44,13 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in); +#if MICROPY_STREAMS_NON_BLOCK // TODO: This is POSIX-specific (but then POSIX is the only real thing, // and anything else just emulates it, right?) #define is_nonblocking_error(errno) ((errno) == EAGAIN || (errno) == EWOULDBLOCK) +#else +#define is_nonblocking_error(errno) (0) +#endif STATIC mp_obj_t stream_read(uint n_args, const mp_obj_t *args) { struct _mp_obj_base_t *o = (struct _mp_obj_base_t *)args[0]; diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index b15fa63043..41bc6a3937 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -39,6 +39,7 @@ #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) #define MICROPY_PATH_MAX (PATH_MAX) +#define MICROPY_STREAMS_NON_BLOCK (1) #define MICROPY_USE_COMPUTED_GOTO (1) #define MICROPY_MOD_SYS_STDFILES (1) #define MICROPY_ENABLE_MOD_CMATH (1)