diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-07-27 00:39:10 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-07-27 00:39:10 +0300 |
commit | a60b0263ba97f655c01f0982df74299c14457b1c (patch) | |
tree | cc333ad6ee02c024c0cfa4b74d267ed1e2d38297 | |
parent | ade36806c8b81cd6509b6823b908e38ae747805f (diff) | |
download | micropython-a60b0263ba97f655c01f0982df74299c14457b1c.tar.gz micropython-a60b0263ba97f655c01f0982df74299c14457b1c.zip |
py/stream: Implement generic flush() method, in terms of C-level ioctl.
-rw-r--r-- | py/stream.c | 11 | ||||
-rw-r--r-- | py/stream.h | 1 |
2 files changed, 12 insertions, 0 deletions
diff --git a/py/stream.c b/py/stream.c index 48f31d401c..0511ef32c3 100644 --- a/py/stream.c +++ b/py/stream.c @@ -477,6 +477,17 @@ STATIC mp_obj_t stream_tell(mp_obj_t self) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_tell_obj, stream_tell); +STATIC mp_obj_t stream_flush(mp_obj_t self) { + const mp_stream_p_t *stream_p = mp_get_stream_raise(self, MP_STREAM_OP_IOCTL); + int error; + mp_uint_t res = stream_p->ioctl(self, MP_STREAM_FLUSH, 0, &error); + if (res == MP_STREAM_ERROR) { + nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(error))); + } + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_flush_obj, stream_flush); + STATIC mp_obj_t stream_ioctl(size_t n_args, const mp_obj_t *args) { const mp_stream_p_t *stream_p = mp_get_stream_raise(args[0], MP_STREAM_OP_IOCTL); diff --git a/py/stream.h b/py/stream.h index 28e0d2dae2..d1074986a3 100644 --- a/py/stream.h +++ b/py/stream.h @@ -58,6 +58,7 @@ MP_DECLARE_CONST_FUN_OBJ(mp_stream_write_obj); MP_DECLARE_CONST_FUN_OBJ(mp_stream_write1_obj); MP_DECLARE_CONST_FUN_OBJ(mp_stream_seek_obj); MP_DECLARE_CONST_FUN_OBJ(mp_stream_tell_obj); +MP_DECLARE_CONST_FUN_OBJ(mp_stream_flush_obj); MP_DECLARE_CONST_FUN_OBJ(mp_stream_ioctl_obj); // these are for mp_get_stream_raise and can be or'd together |