extmod/modnetwork: Add extended socket state.

This commit is contained in:
iabdalkader 2021-08-22 17:29:35 +02:00 committed by Damien George
parent d889f672da
commit e7429389a6
2 changed files with 12 additions and 0 deletions

View File

@ -85,9 +85,15 @@ typedef struct _mod_network_socket_obj_t {
uint8_t domain;
uint8_t type;
int8_t fileno;
uint8_t bound;
} u_param;
mp_uint_t u_state;
};
#if MICROPY_PY_USOCKET_EXTENDED_STATE
// Extended socket state for NICs/ports that need it.
int32_t timeout;
void *state;
#endif
} mod_network_socket_obj_t;
extern const mod_network_nic_type_t mod_network_nic_type_wiznet5k;

View File

@ -54,6 +54,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t
s->u_param.domain = MOD_NETWORK_AF_INET;
s->u_param.type = MOD_NETWORK_SOCK_STREAM;
s->u_param.fileno = -1;
s->u_param.bound = false;
if (n_args >= 1) {
s->u_param.domain = mp_obj_get_int(args[0]);
if (n_args >= 2) {
@ -64,6 +65,11 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t
}
}
#if MICROPY_PY_USOCKET_EXTENDED_STATE
s->timeout = 0;
s->state = NULL;
#endif
return MP_OBJ_FROM_PTR(s);
}