|
4 | 4 | * The MIT License (MIT)
|
5 | 5 | *
|
6 | 6 | * Copyright (c) 2016 Paul Sokolovsky
|
7 |
| - * Copyright (c) 2017 Damien P. George |
| 7 | + * Copyright (c) 2017-2019 Damien P. George |
8 | 8 | *
|
9 | 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
10 | 10 | * of this software and associated documentation files (the "Software"), to deal
|
@@ -53,6 +53,45 @@ void mp_uos_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc) {
|
53 | 53 | }
|
54 | 54 | }
|
55 | 55 |
|
| 56 | +uintptr_t mp_uos_dupterm_poll(uintptr_t poll_flags) { |
| 57 | + uintptr_t poll_flags_out = 0; |
| 58 | + |
| 59 | + for (size_t idx = 0; idx < MICROPY_PY_OS_DUPTERM; ++idx) { |
| 60 | + mp_obj_t s = MP_STATE_VM(dupterm_objs[idx]); |
| 61 | + if (s == MP_OBJ_NULL) { |
| 62 | + continue; |
| 63 | + } |
| 64 | + |
| 65 | + int errcode = 0; |
| 66 | + mp_uint_t ret = 0; |
| 67 | + const mp_stream_p_t *stream_p = mp_get_stream(s); |
| 68 | + #if MICROPY_PY_UOS_DUPTERM_BUILTIN_STREAM |
| 69 | + if (mp_uos_dupterm_is_builtin_stream(s)) { |
| 70 | + ret = stream_p->ioctl(s, MP_STREAM_POLL, poll_flags, &errcode); |
| 71 | + } else |
| 72 | + #endif |
| 73 | + { |
| 74 | + nlr_buf_t nlr; |
| 75 | + if (nlr_push(&nlr) == 0) { |
| 76 | + ret = stream_p->ioctl(s, MP_STREAM_POLL, poll_flags, &errcode); |
| 77 | + nlr_pop(); |
| 78 | + } else { |
| 79 | + // Ignore error with ioctl |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + if (ret != MP_STREAM_ERROR) { |
| 84 | + poll_flags_out |= ret; |
| 85 | + if (poll_flags_out == poll_flags) { |
| 86 | + // Finish early if all requested flags are set |
| 87 | + break; |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + return poll_flags_out; |
| 93 | +} |
| 94 | + |
56 | 95 | int mp_uos_dupterm_rx_chr(void) {
|
57 | 96 | for (size_t idx = 0; idx < MICROPY_PY_OS_DUPTERM; ++idx) {
|
58 | 97 | if (MP_STATE_VM(dupterm_objs[idx]) == MP_OBJ_NULL) {
|
|
0 commit comments