|
|
@@ -19,31 +19,15 @@
|
|
|
#include <sys/fcntl.h>
|
|
|
#include <sys/ioctl.h>
|
|
|
#include <sys/unistd.h>
|
|
|
+#include <sys/param.h>
|
|
|
#include <dirent.h>
|
|
|
#include "esp_vfs.h"
|
|
|
#include "esp_log.h"
|
|
|
+#include "port/arch/sys_arch.h"
|
|
|
+#include "lwip/sys.h"
|
|
|
|
|
|
-/*
|
|
|
- * File descriptors visible by the applications are composed of two parts.
|
|
|
- * Lower CONFIG_MAX_FD_BITS bits are used for the actual file descriptor.
|
|
|
- * Next (16 - CONFIG_MAX_FD_BITS - 1) bits are used to identify the VFS this
|
|
|
- * descriptor corresponds to.
|
|
|
- * Highest bit is zero.
|
|
|
- * We can only use 16 bits because newlib stores file descriptor as short int.
|
|
|
- */
|
|
|
-
|
|
|
-#ifndef CONFIG_MAX_FD_BITS
|
|
|
-#define CONFIG_MAX_FD_BITS 12
|
|
|
-#endif
|
|
|
-
|
|
|
-#define MAX_VFS_ID_BITS (16 - CONFIG_MAX_FD_BITS - 1)
|
|
|
-// mask of actual file descriptor (e.g. 0x00000fff)
|
|
|
-#define VFS_FD_MASK ((1 << CONFIG_MAX_FD_BITS) - 1)
|
|
|
-// max number of VFS entries
|
|
|
-#define VFS_MAX_COUNT ((1 << MAX_VFS_ID_BITS) - 1)
|
|
|
-// mask of VFS id (e.g. 0x00007000)
|
|
|
-#define VFS_INDEX_MASK (VFS_MAX_COUNT << CONFIG_MAX_FD_BITS)
|
|
|
-#define VFS_INDEX_S CONFIG_MAX_FD_BITS
|
|
|
+#define VFS_MAX_COUNT 8 /* max number of VFS entries (registered filesystems) */
|
|
|
+#define MIN_LWIP_FD (FD_SETSIZE - CONFIG_LWIP_MAX_SOCKETS)
|
|
|
|
|
|
#define LEN_PATH_PREFIX_IGNORED SIZE_MAX /* special length value for VFS which is never recognised by open() */
|
|
|
|
|
|
@@ -55,10 +39,19 @@ typedef struct vfs_entry_ {
|
|
|
int offset; // index of this structure in s_vfs array
|
|
|
} vfs_entry_t;
|
|
|
|
|
|
+typedef struct {
|
|
|
+ bool isset; // none or at least one bit is set in the following 3 fd sets
|
|
|
+ fd_set readfds;
|
|
|
+ fd_set writefds;
|
|
|
+ fd_set errorfds;
|
|
|
+} fds_triple_t;
|
|
|
+
|
|
|
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, int *p_minimum_fd, int *p_maximum_fd)
|
|
|
+static short fd_vfs[FD_SETSIZE] = { [0 ... FD_SETSIZE-1] = -1 };
|
|
|
+
|
|
|
+static esp_err_t esp_vfs_register_common(const char* base_path, size_t len, const esp_vfs_t* vfs, void* ctx, int *vfs_entry_index)
|
|
|
{
|
|
|
if (len != LEN_PATH_PREFIX_IGNORED) {
|
|
|
if ((len != 0 && len < 2) || (len > ESP_VFS_PATH_MAX)) {
|
|
|
@@ -96,11 +89,8 @@ static esp_err_t esp_vfs_register_common(const char* base_path, size_t len, cons
|
|
|
entry->ctx = ctx;
|
|
|
entry->offset = index;
|
|
|
|
|
|
- if (p_minimum_fd != NULL) {
|
|
|
- *p_minimum_fd = index << VFS_INDEX_S;
|
|
|
- }
|
|
|
- if (p_maximum_fd != NULL) {
|
|
|
- *p_maximum_fd = (index + 1) << VFS_INDEX_S;
|
|
|
+ if (vfs_entry_index) {
|
|
|
+ *vfs_entry_index = index;
|
|
|
}
|
|
|
|
|
|
return ESP_OK;
|
|
|
@@ -108,12 +98,29 @@ static esp_err_t esp_vfs_register_common(const char* base_path, size_t len, cons
|
|
|
|
|
|
esp_err_t esp_vfs_register(const char* base_path, const esp_vfs_t* vfs, void* ctx)
|
|
|
{
|
|
|
- return esp_vfs_register_common(base_path, strlen(base_path), vfs, ctx, NULL, NULL);
|
|
|
+ return esp_vfs_register_common(base_path, strlen(base_path), vfs, ctx, NULL);
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
+ int index = -1;
|
|
|
+ esp_err_t ret = esp_vfs_register_common("", LEN_PATH_PREFIX_IGNORED, vfs, ctx, &index);
|
|
|
+
|
|
|
+ if (ret == ESP_OK) {
|
|
|
+ if (p_min_fd != NULL) {
|
|
|
+ *p_min_fd = MIN_LWIP_FD;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (p_max_fd != NULL) {
|
|
|
+ *p_max_fd = FD_SETSIZE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = MIN_LWIP_FD; i < FD_SETSIZE; ++i) {
|
|
|
+ fd_vfs[i] = index;
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
esp_err_t esp_vfs_unregister(const char* base_path)
|
|
|
@@ -126,27 +133,40 @@ esp_err_t esp_vfs_unregister(const char* base_path)
|
|
|
if (memcmp(base_path, vfs->path_prefix, vfs->path_prefix_len) == 0) {
|
|
|
free(vfs);
|
|
|
s_vfs[i] = NULL;
|
|
|
+
|
|
|
+ // Delete all references from the FD lookup-table
|
|
|
+ for (int j = 0; j < FD_SETSIZE; ++j) {
|
|
|
+ if (fd_vfs[j] == i) {
|
|
|
+ fd_vfs[j] = -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
}
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
}
|
|
|
|
|
|
-static const vfs_entry_t* get_vfs_for_fd(int fd)
|
|
|
+static inline const vfs_entry_t* get_vfs_for_index(int index)
|
|
|
{
|
|
|
- int index = ((fd & VFS_INDEX_MASK) >> VFS_INDEX_S);
|
|
|
- if (index >= s_vfs_count) {
|
|
|
+ if (index < 0 || index >= s_vfs_count) {
|
|
|
return NULL;
|
|
|
+ } else {
|
|
|
+ return s_vfs[index];
|
|
|
}
|
|
|
- return s_vfs[index];
|
|
|
}
|
|
|
|
|
|
-static int translate_fd(const vfs_entry_t* vfs, int fd)
|
|
|
+static inline bool fd_valid(int fd)
|
|
|
+{
|
|
|
+ return (fd < FD_SETSIZE) && (fd >= 0);
|
|
|
+}
|
|
|
+
|
|
|
+static inline const vfs_entry_t* get_vfs_for_fd(int fd)
|
|
|
{
|
|
|
- if (vfs->vfs.flags & ESP_VFS_FLAG_SHARED_FD_SPACE) {
|
|
|
- return fd;
|
|
|
+ if (fd_valid(fd)) {
|
|
|
+ return get_vfs_for_index(fd_vfs[fd]);
|
|
|
} else {
|
|
|
- return fd & VFS_FD_MASK;
|
|
|
+ return NULL;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -256,10 +276,15 @@ int esp_vfs_open(struct _reent *r, const char * path, int flags, int mode)
|
|
|
const char* path_within_vfs = translate_path(vfs, path);
|
|
|
int ret;
|
|
|
CHECK_AND_CALL(ret, r, vfs, open, path_within_vfs, flags, mode);
|
|
|
- if (ret < 0) {
|
|
|
- return ret;
|
|
|
+ if (ret >= MIN_LWIP_FD) {
|
|
|
+ CHECK_AND_CALL(ret, r, vfs, close, ret);
|
|
|
+ __errno_r(r) = ENFILE;
|
|
|
+ return -1;
|
|
|
}
|
|
|
- return ret + (vfs->offset << VFS_INDEX_S);
|
|
|
+ if (ret >= 0) {
|
|
|
+ fd_vfs[ret] = vfs->offset;
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
ssize_t esp_vfs_write(struct _reent *r, int fd, const void * data, size_t size)
|
|
|
@@ -269,9 +294,8 @@ ssize_t esp_vfs_write(struct _reent *r, int fd, const void * data, size_t size)
|
|
|
__errno_r(r) = EBADF;
|
|
|
return -1;
|
|
|
}
|
|
|
- int local_fd = translate_fd(vfs, fd);
|
|
|
ssize_t ret;
|
|
|
- CHECK_AND_CALL(ret, r, vfs, write, local_fd, data, size);
|
|
|
+ CHECK_AND_CALL(ret, r, vfs, write, fd, data, size);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
@@ -282,9 +306,8 @@ off_t esp_vfs_lseek(struct _reent *r, int fd, off_t size, int mode)
|
|
|
__errno_r(r) = EBADF;
|
|
|
return -1;
|
|
|
}
|
|
|
- int local_fd = translate_fd(vfs, fd);
|
|
|
off_t ret;
|
|
|
- CHECK_AND_CALL(ret, r, vfs, lseek, local_fd, size, mode);
|
|
|
+ CHECK_AND_CALL(ret, r, vfs, lseek, fd, size, mode);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
@@ -295,9 +318,8 @@ ssize_t esp_vfs_read(struct _reent *r, int fd, void * dst, size_t size)
|
|
|
__errno_r(r) = EBADF;
|
|
|
return -1;
|
|
|
}
|
|
|
- int local_fd = translate_fd(vfs, fd);
|
|
|
ssize_t ret;
|
|
|
- CHECK_AND_CALL(ret, r, vfs, read, local_fd, dst, size);
|
|
|
+ CHECK_AND_CALL(ret, r, vfs, read, fd, dst, size);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
@@ -309,9 +331,13 @@ int esp_vfs_close(struct _reent *r, int fd)
|
|
|
__errno_r(r) = EBADF;
|
|
|
return -1;
|
|
|
}
|
|
|
- int local_fd = translate_fd(vfs, fd);
|
|
|
int ret;
|
|
|
- CHECK_AND_CALL(ret, r, vfs, close, local_fd);
|
|
|
+ CHECK_AND_CALL(ret, r, vfs, close, fd);
|
|
|
+ if (fd < MIN_LWIP_FD) {
|
|
|
+ fd_vfs[fd] = -1;
|
|
|
+ } // else { Leave alone socket FDs because sockets are not created by
|
|
|
+ // esp_vfs_open and therefore fd_vfs won't be set again.
|
|
|
+ //}
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
@@ -322,9 +348,8 @@ int esp_vfs_fstat(struct _reent *r, int fd, struct stat * st)
|
|
|
__errno_r(r) = EBADF;
|
|
|
return -1;
|
|
|
}
|
|
|
- int local_fd = translate_fd(vfs, fd);
|
|
|
int ret;
|
|
|
- CHECK_AND_CALL(ret, r, vfs, fstat, local_fd, st);
|
|
|
+ CHECK_AND_CALL(ret, r, vfs, fstat, fd, st);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
@@ -404,14 +429,14 @@ DIR* opendir(const char* name)
|
|
|
DIR* ret;
|
|
|
CHECK_AND_CALLP(ret, r, vfs, opendir, path_within_vfs);
|
|
|
if (ret != NULL) {
|
|
|
- ret->dd_vfs_idx = vfs->offset << VFS_INDEX_S;
|
|
|
+ ret->dd_vfs_idx = vfs->offset;
|
|
|
}
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
struct dirent* readdir(DIR* pdir)
|
|
|
{
|
|
|
- const vfs_entry_t* vfs = get_vfs_for_fd(pdir->dd_vfs_idx);
|
|
|
+ const vfs_entry_t* vfs = get_vfs_for_index(pdir->dd_vfs_idx);
|
|
|
struct _reent* r = __getreent();
|
|
|
if (vfs == NULL) {
|
|
|
__errno_r(r) = EBADF;
|
|
|
@@ -424,7 +449,7 @@ struct dirent* readdir(DIR* pdir)
|
|
|
|
|
|
int readdir_r(DIR* pdir, struct dirent* entry, struct dirent** out_dirent)
|
|
|
{
|
|
|
- const vfs_entry_t* vfs = get_vfs_for_fd(pdir->dd_vfs_idx);
|
|
|
+ const vfs_entry_t* vfs = get_vfs_for_index(pdir->dd_vfs_idx);
|
|
|
struct _reent* r = __getreent();
|
|
|
if (vfs == NULL) {
|
|
|
errno = EBADF;
|
|
|
@@ -437,7 +462,7 @@ int readdir_r(DIR* pdir, struct dirent* entry, struct dirent** out_dirent)
|
|
|
|
|
|
long telldir(DIR* pdir)
|
|
|
{
|
|
|
- const vfs_entry_t* vfs = get_vfs_for_fd(pdir->dd_vfs_idx);
|
|
|
+ const vfs_entry_t* vfs = get_vfs_for_index(pdir->dd_vfs_idx);
|
|
|
struct _reent* r = __getreent();
|
|
|
if (vfs == NULL) {
|
|
|
errno = EBADF;
|
|
|
@@ -450,7 +475,7 @@ long telldir(DIR* pdir)
|
|
|
|
|
|
void seekdir(DIR* pdir, long loc)
|
|
|
{
|
|
|
- const vfs_entry_t* vfs = get_vfs_for_fd(pdir->dd_vfs_idx);
|
|
|
+ const vfs_entry_t* vfs = get_vfs_for_index(pdir->dd_vfs_idx);
|
|
|
struct _reent* r = __getreent();
|
|
|
if (vfs == NULL) {
|
|
|
errno = EBADF;
|
|
|
@@ -466,7 +491,7 @@ void rewinddir(DIR* pdir)
|
|
|
|
|
|
int closedir(DIR* pdir)
|
|
|
{
|
|
|
- const vfs_entry_t* vfs = get_vfs_for_fd(pdir->dd_vfs_idx);
|
|
|
+ const vfs_entry_t* vfs = get_vfs_for_index(pdir->dd_vfs_idx);
|
|
|
struct _reent* r = __getreent();
|
|
|
if (vfs == NULL) {
|
|
|
errno = EBADF;
|
|
|
@@ -513,11 +538,10 @@ int fcntl(int fd, int cmd, ...)
|
|
|
__errno_r(r) = EBADF;
|
|
|
return -1;
|
|
|
}
|
|
|
- int local_fd = translate_fd(vfs, fd);
|
|
|
int ret;
|
|
|
va_list args;
|
|
|
va_start(args, cmd);
|
|
|
- CHECK_AND_CALL(ret, r, vfs, fcntl, local_fd, cmd, args);
|
|
|
+ CHECK_AND_CALL(ret, r, vfs, fcntl, fd, cmd, args);
|
|
|
va_end(args);
|
|
|
return ret;
|
|
|
}
|
|
|
@@ -530,11 +554,10 @@ int ioctl(int fd, int cmd, ...)
|
|
|
__errno_r(r) = EBADF;
|
|
|
return -1;
|
|
|
}
|
|
|
- int local_fd = translate_fd(vfs, fd);
|
|
|
int ret;
|
|
|
va_list args;
|
|
|
va_start(args, cmd);
|
|
|
- CHECK_AND_CALL(ret, r, vfs, ioctl, local_fd, cmd, args);
|
|
|
+ CHECK_AND_CALL(ret, r, vfs, ioctl, fd, cmd, args);
|
|
|
va_end(args);
|
|
|
return ret;
|
|
|
}
|
|
|
@@ -547,8 +570,166 @@ int fsync(int fd)
|
|
|
__errno_r(r) = EBADF;
|
|
|
return -1;
|
|
|
}
|
|
|
- int local_fd = translate_fd(vfs, fd);
|
|
|
int ret;
|
|
|
- CHECK_AND_CALL(ret, r, vfs, fsync, local_fd);
|
|
|
+ CHECK_AND_CALL(ret, r, vfs, fsync, fd);
|
|
|
return ret;
|
|
|
}
|
|
|
+
|
|
|
+static void call_end_selects(int end_index, const fds_triple_t *vfs_fds_triple)
|
|
|
+{
|
|
|
+ for (int i = 0; i < end_index; ++i) {
|
|
|
+ const vfs_entry_t *vfs = get_vfs_for_index(i);
|
|
|
+ const fds_triple_t *item = &vfs_fds_triple[i];
|
|
|
+ if (vfs && vfs->vfs.end_select && item->isset) {
|
|
|
+ vfs->vfs.end_select();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static int set_global_fd_sets(const fds_triple_t *vfs_fds_triple, int size, fd_set *readfds, fd_set *writefds, fd_set *errorfds)
|
|
|
+{
|
|
|
+ int ret = 0;
|
|
|
+
|
|
|
+ for (int i = 0; i < size; ++i) {
|
|
|
+ const fds_triple_t *item = &vfs_fds_triple[i];
|
|
|
+ if (item->isset) {
|
|
|
+ for (int j = 0; j < sizeof(item->readfds.fds_bits)/sizeof(item->readfds.fds_bits[0]); ++j) {
|
|
|
+ if (readfds != NULL) {
|
|
|
+ readfds->fds_bits[j] |= item->readfds.fds_bits[j];
|
|
|
+ ret += __builtin_popcountl(item->readfds.fds_bits[j]);
|
|
|
+ }
|
|
|
+ if (writefds != NULL) {
|
|
|
+ writefds->fds_bits[j] |= item->writefds.fds_bits[j];
|
|
|
+ ret += __builtin_popcountl(item->writefds.fds_bits[j]);
|
|
|
+ }
|
|
|
+ if (errorfds != NULL) {
|
|
|
+ errorfds->fds_bits[j] |= item->errorfds.fds_bits[j];
|
|
|
+ ret += __builtin_popcountl(item->errorfds.fds_bits[j]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+int esp_vfs_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout)
|
|
|
+{
|
|
|
+ const int non_socket_nfds = MIN(nfds, MIN_LWIP_FD);
|
|
|
+ int ret = 0;
|
|
|
+ struct _reent* r = __getreent();
|
|
|
+
|
|
|
+ if (nfds > FD_SETSIZE || nfds < 0) {
|
|
|
+ __errno_r(r) = EINVAL;
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ fds_triple_t *vfs_fds_triple;
|
|
|
+ if ((vfs_fds_triple = calloc(s_vfs_count, sizeof(fds_triple_t))) == NULL) {
|
|
|
+ __errno_r(r) = ENOMEM;
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < non_socket_nfds; ++i) {
|
|
|
+ if (fd_vfs[i] < 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ fds_triple_t *item = &vfs_fds_triple[fd_vfs[i]]; // FD sets for VFS which belongs to FD i
|
|
|
+ if (readfds && FD_ISSET(i, readfds)) {
|
|
|
+ item->isset = true;
|
|
|
+ FD_SET(i, &item->readfds);
|
|
|
+ FD_CLR(i, readfds);
|
|
|
+ }
|
|
|
+ if (writefds && FD_ISSET(i, writefds)) {
|
|
|
+ item->isset = true;
|
|
|
+ FD_SET(i, &item->writefds);
|
|
|
+ FD_CLR(i, writefds);
|
|
|
+ }
|
|
|
+ if (errorfds && FD_ISSET(i, errorfds)) {
|
|
|
+ item->isset = true;
|
|
|
+ FD_SET(i, &item->errorfds);
|
|
|
+ FD_CLR(i, errorfds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // all non-socket VFSs have their FD sets in vfs_fds_triple
|
|
|
+ // the global readfds, writefds and errorfds contain only socket FDs
|
|
|
+
|
|
|
+ void *callback_handle = sys_thread_sem_get();
|
|
|
+ if (!callback_handle) {
|
|
|
+ __errno_r(r) = ENOMEM;
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ sys_arch_sem_wait(callback_handle, 1); //ensure the semaphore is taken so we are not signalled out-of-sequence; 0 timeout would block forever
|
|
|
+ for (int i = 0; i < s_vfs_count; ++i) {
|
|
|
+ const vfs_entry_t *vfs = get_vfs_for_index(i);
|
|
|
+ fds_triple_t *item = &vfs_fds_triple[i];
|
|
|
+
|
|
|
+ if (vfs && vfs->vfs.start_select && item->isset) {
|
|
|
+ // call start_select for all non-socket VFSs with has at least one FD set in readfds, writefds, or errorfds
|
|
|
+ // note: it can point to socket VFS but item->isset will be false for that
|
|
|
+ esp_err_t err = vfs->vfs.start_select(nfds, &item->readfds, &item->writefds, &item->errorfds, callback_handle);
|
|
|
+
|
|
|
+ if (err != ESP_OK) {
|
|
|
+ call_end_selects(i, vfs_fds_triple);
|
|
|
+ (void) set_global_fd_sets(vfs_fds_triple, s_vfs_count, readfds, writefds, errorfds);
|
|
|
+ free(vfs_fds_triple);
|
|
|
+ __errno_r(r) = ENOMEM;
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ int socket_select_called = 0;
|
|
|
+ for (int i = MIN_LWIP_FD; i < FD_SETSIZE; ++i) {
|
|
|
+ const vfs_entry_t* vfs = get_vfs_for_fd(i);
|
|
|
+ if (vfs != NULL && vfs->vfs.socket_select != NULL) {
|
|
|
+ // find socket VFS and call socket_select
|
|
|
+ ret = vfs->vfs.socket_select(nfds, readfds, writefds, errorfds, timeout);
|
|
|
+ socket_select_called = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!socket_select_called) {
|
|
|
+ uint32_t timeout_ms = 0;
|
|
|
+
|
|
|
+ if (readfds) {
|
|
|
+ FD_ZERO(readfds);
|
|
|
+ }
|
|
|
+ if (writefds) {
|
|
|
+ FD_ZERO(writefds);
|
|
|
+ }
|
|
|
+ if (errorfds) {
|
|
|
+ FD_ZERO(errorfds);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (timeout) {
|
|
|
+ timeout_ms = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
|
|
|
+ timeout_ms = MAX(timeout_ms, 1); //make sure it is not 0 which would be in infinite wait
|
|
|
+ }
|
|
|
+ sys_arch_sem_wait(callback_handle, timeout_ms);
|
|
|
+ sys_sem_free(callback_handle);
|
|
|
+ }
|
|
|
+
|
|
|
+ call_end_selects(s_vfs_count, vfs_fds_triple); // for VFSs for start_select was called before
|
|
|
+ if (ret >= 0) {
|
|
|
+ ret += set_global_fd_sets(vfs_fds_triple, s_vfs_count, readfds, writefds, errorfds);
|
|
|
+ }
|
|
|
+ //don't free callback_handle because it is freed in lwip_select (vfs.socket_select)
|
|
|
+ free(vfs_fds_triple);
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+void esp_vfs_select_triggered(void *callback_handle)
|
|
|
+{
|
|
|
+ if (callback_handle) {
|
|
|
+ sys_sem_signal(callback_handle); //vfs->vfs.socket_select will return
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void esp_vfs_select_triggered_isr(void *callback_handle, BaseType_t *woken)
|
|
|
+{
|
|
|
+ if (callback_handle && sys_sem_signal_isr(callback_handle) && woken) {
|
|
|
+ *woken = pdTRUE;
|
|
|
+ }
|
|
|
+}
|