Skip to content

Commit 91031a7

Browse files
committed
extmod/modlwip: lwip_socket_setsockopt: Handle option value properly.
1 parent 4332d72 commit 91031a7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

extmod/modlwip.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
#ifndef ip_set_option
4949
#define ip_set_option(pcb, opt) ((pcb)->so_options |= (opt))
5050
#endif
51+
#ifndef ip_reset_option
52+
#define ip_reset_option(pcb, opt) ((pcb)->so_options &= ~(opt))
53+
#endif
5154

5255
#ifdef MICROPY_PY_LWIP_SLIP
5356
#include "netif/slipif.h"
@@ -941,8 +944,11 @@ STATIC mp_obj_t lwip_socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
941944
switch (mp_obj_get_int(args[2])) {
942945
case SOF_REUSEADDR:
943946
// Options are common for UDP and TCP pcb's.
944-
// TODO: handle val
945-
ip_set_option(socket->pcb.tcp, SOF_REUSEADDR);
947+
if (val) {
948+
ip_set_option(socket->pcb.tcp, SOF_REUSEADDR);
949+
} else {
950+
ip_reset_option(socket->pcb.tcp, SOF_REUSEADDR);
951+
}
946952
break;
947953
default:
948954
printf("Warning: lwip.setsockopt() not implemented\n");

0 commit comments

Comments
 (0)