diff --git a/components/lwip/include/lwip/lwip/sockets.h b/components/lwip/include/lwip/lwip/sockets.h index 10e8ace03..cb458988a 100755 --- a/components/lwip/include/lwip/lwip/sockets.h +++ b/components/lwip/include/lwip/lwip/sockets.h @@ -431,9 +431,9 @@ typedef struct ip_mreq { /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */ #define FD_SETSIZE MEMP_NUM_NETCONN #define FDSETSAFESET(n, code) do { \ - if (n >= LWIP_SOCKET_OFFSET && ((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \ + if (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \ code; }} while(0) -#define FDSETSAFEGET(n, code) (n >= LWIP_SOCKET_OFFSET && ((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0) ?\ +#define FDSETSAFEGET(n, code) (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0) ?\ (code) : 0) #define FD_SET(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] |= (1 << (((n)-LWIP_SOCKET_OFFSET) & 7))) #define FD_CLR(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] &= ~(1 << (((n)-LWIP_SOCKET_OFFSET) & 7))) diff --git a/components/lwip/include/lwip/port/arch/vfs_lwip.h b/components/lwip/include/lwip/port/arch/vfs_lwip.h index 59ed087c5..88714b03b 100644 --- a/components/lwip/include/lwip/port/arch/vfs_lwip.h +++ b/components/lwip/include/lwip/port/arch/vfs_lwip.h @@ -19,7 +19,7 @@ extern "C" { /* Internal declarations used to ingreate LWIP port layer to ESP-IDF VFS for POSIX I/O. */ -extern unsigned lwip_socket_offset; +extern int lwip_socket_offset; void esp_vfs_lwip_sockets_register(); diff --git a/components/lwip/port/vfs_lwip.c b/components/lwip/port/vfs_lwip.c index b3c626192..aa623f010 100644 --- a/components/lwip/port/vfs_lwip.c +++ b/components/lwip/port/vfs_lwip.c @@ -37,7 +37,7 @@ FDs that the user sees are the same FDs. */ -unsigned lwip_socket_offset; +int lwip_socket_offset; static int lwip_fcntl_r_wrapper(int fd, int cmd, va_list args); static int lwip_ioctl_r_wrapper(int fd, int cmd, va_list args); @@ -54,14 +54,14 @@ void esp_vfs_lwip_sockets_register() .fcntl = &lwip_fcntl_r_wrapper, .ioctl = &lwip_ioctl_r_wrapper, }; - unsigned max_fd; + int max_fd; ESP_ERROR_CHECK(esp_vfs_register_socket_space(&vfs, NULL, &lwip_socket_offset, &max_fd)); /* LWIP can't be allowed to create more sockets than fit in the per-VFS fd space. Currently this isn't configurable * but it's set much larger than CONFIG_LWIP_MAX_SOCKETS should ever be (max 2^12 FDs). */ - assert(CONFIG_LWIP_MAX_SOCKETS <= max_fd - lwip_socket_offset); + assert(max_fd >= lwip_socket_offset && CONFIG_LWIP_MAX_SOCKETS <= max_fd - lwip_socket_offset); } static int lwip_fcntl_r_wrapper(int fd, int cmd, va_list args) diff --git a/components/vfs/include/esp_vfs.h b/components/vfs/include/esp_vfs.h index 9cd8e5e56..ab645fccf 100644 --- a/components/vfs/include/esp_vfs.h +++ b/components/vfs/include/esp_vfs.h @@ -205,7 +205,7 @@ esp_err_t esp_vfs_register(const char* base_path, const esp_vfs_t* vfs, void* ct * @return ESP_OK if successful, ESP_ERR_NO_MEM if too many VFSes are * registered. */ -esp_err_t esp_vfs_register_socket_space(const esp_vfs_t *vfs, void *ctx, unsigned *p_min_fd, unsigned *p_max_fd); +esp_err_t esp_vfs_register_socket_space(const esp_vfs_t *vfs, void *ctx, int *p_min_fd, int *p_max_fd); /** * Unregister a virtual filesystem for given path prefix diff --git a/components/vfs/vfs.c b/components/vfs/vfs.c index 92f60b602..2a69df78a 100644 --- a/components/vfs/vfs.c +++ b/components/vfs/vfs.c @@ -54,7 +54,7 @@ typedef struct vfs_entry_ { static vfs_entry_t* s_vfs[VFS_MAX_COUNT] = { 0 }; static size_t s_vfs_count = 0; -static esp_err_t esp_vfs_register_common(const char* base_path, size_t len, const esp_vfs_t* vfs, void* ctx, unsigned *p_minimum_fd, unsigned *p_maximum_fd) +static esp_err_t esp_vfs_register_common(const char* base_path, size_t len, const esp_vfs_t* vfs, void* ctx, int *p_minimum_fd, int *p_maximum_fd) { if (len != LEN_PATH_PREFIX_IGNORED) { if ((len != 0 && len < 2) || (len > ESP_VFS_PATH_MAX)) { @@ -107,7 +107,7 @@ esp_err_t esp_vfs_register(const char* base_path, const esp_vfs_t* vfs, void* ct return esp_vfs_register_common(base_path, strlen(base_path), vfs, ctx, NULL, NULL); } -esp_err_t esp_vfs_register_socket_space(const esp_vfs_t *vfs, void *ctx, unsigned *p_min_fd, unsigned *p_max_fd) +esp_err_t esp_vfs_register_socket_space(const esp_vfs_t *vfs, void *ctx, int *p_min_fd, int *p_max_fd) { return esp_vfs_register_common("", LEN_PATH_PREFIX_IGNORED, vfs, ctx, p_min_fd, p_max_fd); }