Skip to content

Commit cb53226

Browse files
committed
extmod/modlwip: Add ioctl method to socket, with poll implementation.
Implementation of polling may need further fine tuning, but basic functionality works (tested on esp8266).
1 parent 2d329c4 commit cb53226

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

extmod/modlwip.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,34 @@ STATIC mp_uint_t lwip_socket_write(mp_obj_t self_in, const void *buf, mp_uint_t
11271127
return MP_STREAM_ERROR;
11281128
}
11291129

1130+
STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
1131+
lwip_socket_obj_t *socket = self_in;
1132+
mp_uint_t ret;
1133+
1134+
if (request == MP_STREAM_POLL) {
1135+
uintptr_t flags = arg;
1136+
ret = 0;
1137+
1138+
if (flags & MP_STREAM_POLL_RD && socket->incoming.pbuf != NULL) {
1139+
ret |= MP_STREAM_POLL_RD;
1140+
}
1141+
1142+
if (flags & MP_STREAM_POLL_WR && tcp_sndbuf(socket->pcb.tcp) > 0) {
1143+
ret |= MP_STREAM_POLL_WR;
1144+
}
1145+
1146+
if (flags & MP_STREAM_POLL_HUP && socket->state == STATE_PEER_CLOSED) {
1147+
ret |= MP_STREAM_POLL_HUP;
1148+
}
1149+
1150+
} else {
1151+
*errcode = MP_EINVAL;
1152+
ret = MP_STREAM_ERROR;
1153+
}
1154+
1155+
return ret;
1156+
}
1157+
11301158
STATIC const mp_map_elem_t lwip_socket_locals_dict_table[] = {
11311159
{ MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)&lwip_socket_close_obj },
11321160
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&lwip_socket_close_obj },
@@ -1153,6 +1181,7 @@ STATIC MP_DEFINE_CONST_DICT(lwip_socket_locals_dict, lwip_socket_locals_dict_tab
11531181
STATIC const mp_stream_p_t lwip_socket_stream_p = {
11541182
.read = lwip_socket_read,
11551183
.write = lwip_socket_write,
1184+
.ioctl = lwip_socket_ioctl,
11561185
};
11571186

11581187
STATIC const mp_obj_type_t lwip_socket_type = {

0 commit comments

Comments
 (0)