diff options
| author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-03-25 17:44:24 +0200 | 
|---|---|---|
| committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-03-25 17:44:24 +0200 | 
| commit | 5e75f335e6df01cddfc2cd8db24d5807e73c13a6 (patch) | |
| tree | 8a15baca3dc1f2727ed433a04b80a5efd353992e | |
| parent | 0cb10b52205f244cf3f35fe65f6f1d0fd2fed384 (diff) | |
extmod/modlwip: Implement setsocketopt(SO_REUSEADDR).
| -rw-r--r-- | extmod/modlwip.c | 17 | 
1 files changed, 16 insertions, 1 deletions
| diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 0355342e7..bce5d9f88 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -44,6 +44,11 @@  //#include "lwip/raw.h"  #include "lwip/dns.h" +// For compatibilily with older lwIP versions. +#ifndef ip_set_option +#define ip_set_option(pcb, opt)   ((pcb)->so_options |= (opt)) +#endif +  #ifdef MICROPY_PY_LWIP_SLIP  #include "netif/slipif.h"  #include "lwip/sio.h" @@ -876,7 +881,17 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_setblocking_obj, lwip_socket_setblo  STATIC mp_obj_t lwip_socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {      (void)n_args; // always 4 -    printf("Warning: lwip.setsockopt() not implemented\n"); +    lwip_socket_obj_t *socket = args[0]; +    mp_int_t val = mp_obj_get_int(args[3]); +    switch (mp_obj_get_int(args[2])) { +        case SOF_REUSEADDR: +            // Options are common for UDP and TCP pcb's. +            // TODO: handle val +            ip_set_option(socket->pcb.tcp, SOF_REUSEADDR); +            break; +        default: +            printf("Warning: lwip.setsockopt() not implemented\n"); +    }      return mp_const_none;  }  STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_socket_setsockopt_obj, 4, 4, lwip_socket_setsockopt); | 
