diff options
| author | iabdalkader <i.abdalkader@gmail.com> | 2023-11-02 09:10:38 +0100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-12-06 17:32:00 +1100 |
| commit | 50f31cc902d284db9f6ddbd60101608cfdbdbe7b (patch) | |
| tree | 4ef3f2e20d26c8da21b4ecc4346cba44603a3dbe | |
| parent | d30d5c99afba705e8286e9177768e0e38db59fff (diff) | |
extmod/modnetwork: Add deinit function to NIC protocol.
This is usually called on soft-reboot, a NIC can implement this to do any
necessary cleaning up (such as invalidating root pointers).
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
| -rw-r--r-- | extmod/modnetwork.c | 9 | ||||
| -rw-r--r-- | extmod/modnetwork.h | 1 |
2 files changed, 10 insertions, 0 deletions
diff --git a/extmod/modnetwork.c b/extmod/modnetwork.c index f5734af9b..527d1729e 100644 --- a/extmod/modnetwork.c +++ b/extmod/modnetwork.c @@ -65,6 +65,15 @@ void mod_network_init(void) { } void mod_network_deinit(void) { + #if !MICROPY_PY_LWIP + for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) { + mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i]; + const mod_network_nic_protocol_t *nic_protocol = MP_OBJ_TYPE_GET_SLOT(mp_obj_get_type(nic), protocol); + if (nic_protocol->deinit) { + nic_protocol->deinit(); + } + } + #endif } void mod_network_register_nic(mp_obj_t nic) { diff --git a/extmod/modnetwork.h b/extmod/modnetwork.h index e3239c2a0..0a7897faa 100644 --- a/extmod/modnetwork.h +++ b/extmod/modnetwork.h @@ -80,6 +80,7 @@ struct _mod_network_socket_obj_t; typedef struct _mod_network_nic_protocol_t { // API for non-socket operations int (*gethostbyname)(mp_obj_t nic, const char *name, mp_uint_t len, uint8_t *ip_out); + void (*deinit)(void); // API for socket operations; return -1 on error int (*socket)(struct _mod_network_socket_obj_t *socket, int *_errno); |
