Skip to content

Commit 964ae32

Browse files
committed
extmod/uos_dupterm: Add mp_uos_dupterm_poll to poll all dupterms.
1 parent b7da67c commit 964ae32

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

extmod/misc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_uos_dupterm_obj);
3636

3737
#if MICROPY_PY_OS_DUPTERM
3838
bool mp_uos_dupterm_is_builtin_stream(mp_const_obj_t stream);
39+
uintptr_t mp_uos_dupterm_poll(uintptr_t poll_flags);
3940
int mp_uos_dupterm_rx_chr(void);
4041
void mp_uos_dupterm_tx_strn(const char *str, size_t len);
4142
void mp_uos_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc);

extmod/uos_dupterm.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* The MIT License (MIT)
55
*
66
* Copyright (c) 2016 Paul Sokolovsky
7-
* Copyright (c) 2017 Damien P. George
7+
* Copyright (c) 2017-2019 Damien P. George
88
*
99
* Permission is hereby granted, free of charge, to any person obtaining a copy
1010
* 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) {
5353
}
5454
}
5555

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+
5695
int mp_uos_dupterm_rx_chr(void) {
5796
for (size_t idx = 0; idx < MICROPY_PY_OS_DUPTERM; ++idx) {
5897
if (MP_STATE_VM(dupterm_objs[idx]) == MP_OBJ_NULL) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy