From 2a7a307baaa8b5a1fbd30ccdd8fa393ec0341888 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 31 Jan 2019 11:22:03 +1100 Subject: [PATCH] extmod/modlwip: Add support for polling UDP sockets for writability. --- extmod/modlwip.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 73f1679552..84a1bd3c17 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -1231,9 +1231,15 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_ } } - // Note: pcb.tcp==NULL if state<0, and in this case we can't call tcp_sndbuf - if (flags & MP_STREAM_POLL_WR && socket->pcb.tcp != NULL && tcp_sndbuf(socket->pcb.tcp) > 0) { - ret |= MP_STREAM_POLL_WR; + if (flags & MP_STREAM_POLL_WR) { + if (socket->type == MOD_NETWORK_SOCK_DGRAM && socket->pcb.udp != NULL) { + // UDP socket is writable + ret |= MP_STREAM_POLL_WR; + } else if (socket->pcb.tcp != NULL && tcp_sndbuf(socket->pcb.tcp) > 0) { + // TCP socket is writable + // Note: pcb.tcp==NULL if state<0, and in this case we can't call tcp_sndbuf + ret |= MP_STREAM_POLL_WR; + } } if (socket->state == STATE_NEW) {