Skip to content

Commit ccf4e5a

Browse files
committed
extmod/modwebsocket: Add close() method.
1 parent 497660f commit ccf4e5a

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

extmod/modwebsocket.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,19 @@ STATIC mp_uint_t websocket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t
272272
}
273273
}
274274

275+
STATIC mp_obj_t websocket_close(mp_obj_t self_in) {
276+
mp_obj_websocket_t *self = MP_OBJ_TO_PTR(self_in);
277+
// TODO: Send close signaling to the other side, otherwise it's
278+
// abrupt close (connection abort).
279+
return mp_stream_close(self->sock);
280+
}
281+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(websocket_close_obj, websocket_close);
282+
275283
STATIC const mp_map_elem_t websocket_locals_dict_table[] = {
276284
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj },
277285
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj },
278286
{ MP_OBJ_NEW_QSTR(MP_QSTR_ioctl), (mp_obj_t)&mp_stream_ioctl_obj },
287+
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&websocket_close_obj },
279288
};
280289
STATIC MP_DEFINE_CONST_DICT(websocket_locals_dict, websocket_locals_dict_table);
281290

0 commit comments

Comments
 (0)