extmod/modlwip: Use actual errno in exception for error in listen.

The actual underlying error number raised from the lwIP subsystem when
attempting to listen on a socket is swallowed and replaced with an
out-of-memory error which is confusing.

This commit passes the underlying error message from the lwIP subsystem to
the appropriate OSError exception.
This commit is contained in:
Jared Hancock 2022-11-07 11:21:27 -06:00 committed by Damien George
parent ecd4d54391
commit a2fd382c34
1 changed files with 12 additions and 1 deletions

View File

@ -931,9 +931,20 @@ STATIC mp_obj_t lwip_socket_listen(size_t n_args, const mp_obj_t *args) {
mp_raise_OSError(MP_EOPNOTSUPP); mp_raise_OSError(MP_EOPNOTSUPP);
} }
struct tcp_pcb *new_pcb = tcp_listen_with_backlog(socket->pcb.tcp, (u8_t)backlog); struct tcp_pcb *new_pcb;
#if LWIP_VERSION_MACRO < 0x02000100
new_pcb = tcp_listen_with_backlog(socket->pcb.tcp, (u8_t)backlog);
#else
err_t error;
new_pcb = tcp_listen_with_backlog_and_err(socket->pcb.tcp, (u8_t)backlog, &error);
#endif
if (new_pcb == NULL) { if (new_pcb == NULL) {
#if LWIP_VERSION_MACRO < 0x02000100
mp_raise_OSError(MP_ENOMEM); mp_raise_OSError(MP_ENOMEM);
#else
mp_raise_OSError(error_lookup_table[-error]);
#endif
} }
socket->pcb.tcp = new_pcb; socket->pcb.tcp = new_pcb;