Skip to content

Commit 6837dba

Browse files
committed
extmod/modwebsocket: Allow to get type of last read data using ioctl().
1 parent 0c97e4c commit 6837dba

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

extmod/modwebsocket.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,28 @@ STATIC mp_uint_t websocket_write(mp_obj_t self_in, const void *buf, mp_uint_t si
207207
return out_sz;
208208
}
209209

210+
STATIC mp_uint_t websocket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
211+
mp_obj_websocket_t *self = MP_OBJ_TO_PTR(self_in);
212+
switch (request) {
213+
case MP_STREAM_GET_DATA_OPTS:
214+
return self->ws_flags & FRAME_OPCODE_MASK;
215+
default:
216+
*errcode = EINVAL;
217+
return MP_STREAM_ERROR;
218+
}
219+
}
220+
210221
STATIC const mp_map_elem_t websocket_locals_dict_table[] = {
211222
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj },
212223
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj },
224+
{ MP_OBJ_NEW_QSTR(MP_QSTR_ioctl), (mp_obj_t)&mp_stream_ioctl_obj },
213225
};
214226
STATIC MP_DEFINE_CONST_DICT(websocket_locals_dict, websocket_locals_dict_table);
215227

216228
STATIC const mp_stream_p_t websocket_stream_p = {
217229
.read = websocket_read,
218230
.write = websocket_write,
231+
.ioctl = websocket_ioctl,
219232
};
220233

221234
STATIC const mp_obj_type_t websocket_type = {

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