10000 stream: Make non-blcoking stream support configurable. · micropython/micropython@0ef015b · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ef015b

Browse files
author
Paul Sokolovsky
committed
stream: Make non-blcoking stream support configurable.
Enable only on unix. To avoid unpleasant surprises with error codes.
1 parent 6c62e72 commit 0ef015b

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

py/mpconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ typedef double mp_float_t;
249249
#define MICROPY_PATH_MAX (512)
250250
#endif
251251

252+
// Whether POSIX-semantics non-blocking streams are supported
253+
#ifndef MICROPY_STREAMS_NON_BLOCK
254+
#define MICROPY_STREAMS_NON_BLOCK (0)
255+
#endif
256+
252257
// Whether to use computed gotos in the VM, or a switch
253258
// Computed gotos are roughly 10% faster, and increase VM code size by a little
254259
#ifndef MICROPY_USE_COMPUTED_GOTO

py/stream.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@
2525
*/
2626

2727
#include <string.h>
28-
#include <errno.h>
2928

3029
#include "mpconfig.h"
3130
#include "nlr.h"
3231
#include "misc.h"
3332
#include "qstr.h"
3433
#include "obj.h"
3534
#include "stream.h"
35+
#if MICROPY_STREAMS_NON_BLOCK
36+
#include <errno.h>
37+
#endif
3638

3739
// This file defines generic Python stream read/write methods which
3840
// dispatch to the underlying stream interface of an object.
@@ -42,9 +44,13 @@
4244

4345
STATIC mp_obj_t stream_readall(mp_obj_t self_in);
4446

47+
#if MICROPY_STREAMS_NON_BLOCK
4548
// TODO: This is POSIX-specific (but then POSIX is the only real thing,
4649
// and anything else just emulates it, right?)
4750
#define is_nonblocking_error(errno) ((errno) == EAGAIN || (errno) == EWOULDBLOCK)
51+
#else
52+
#define is_nonblocking_error(errno) (0)
53+
#endif
4854

4955
STATIC mp_obj_t stream_read(uint n_args, const mp_obj_t *args) {
5056
struct _mp_obj_base_t *o = (struct _mp_obj_base_t *)args[0];

unix/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
4040
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
4141
#define MICROPY_PATH_MAX (PATH_MAX)
42+
#define MICROPY_STREAMS_NON_BLOCK (1)
4243
#define MICROPY_USE_COMPUTED_GOTO (1)
4344
#define MICROPY_MOD_SYS_STDFILES (1)
4445
#define MICROPY_ENABLE_MOD_CMATH (1)

0 commit comments

Comments
 (0)
0