Merge branch 'bugfix/vfs_select_incorrect_reset' into 'master'
VFS select: Correct reseting of socket FDs See merge request idf/esp-idf!2444
This commit is contained in:
commit
64b56beff5
5 changed files with 39 additions and 14 deletions
|
@ -38,7 +38,6 @@
|
|||
|
||||
#if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include <sys/select.h>
|
||||
#include <stddef.h> /* for size_t */
|
||||
#include <string.h> /* for FD_ZERO */
|
||||
|
||||
|
@ -590,10 +589,10 @@ static inline int sendto(int s,const void *dataptr,size_t size,int flags,const s
|
|||
{ return lwip_sendto_r(s,dataptr,size,flags,to,tolen); }
|
||||
static inline int socket(int domain,int type,int protocol)
|
||||
{ return lwip_socket(domain,type,protocol); }
|
||||
#ifndef ESP_PLATFORM
|
||||
#ifndef ESP_HAS_SELECT
|
||||
static inline int select(int maxfdp1,fd_set *readset,fd_set *writeset,fd_set *exceptset,struct timeval *timeout)
|
||||
{ return lwip_select(maxfdp1,readset,writeset,exceptset,timeout); }
|
||||
#endif /* ESP_PLATFORM */
|
||||
#endif /* ESP_HAS_SELECT */
|
||||
static inline int ioctlsocket(int s,long cmd,void *argp)
|
||||
{ return lwip_ioctl_r(s,cmd,argp); }
|
||||
|
||||
|
@ -646,10 +645,10 @@ static inline int sendto(int s,const void *dataptr,size_t size,int flags,const s
|
|||
{ return lwip_sendto(s,dataptr,size,flags,to,tolen); }
|
||||
static inline int socket(int domain,int type,int protocol)
|
||||
{ return lwip_socket(domain,type,protocol); }
|
||||
#ifndef ESP_PLATFORM
|
||||
#ifndef ESP_HAS_SELECT
|
||||
static inline int select(int maxfdp1,fd_set t*readset,fd_set *writeset,fd_set *exceptset,struct timeval *timeout)
|
||||
{ return lwip_select(maxfdp1,readset,writeset,exceptset,timeout); }
|
||||
#endif /* ESP_PLATFORM */
|
||||
#endif /* ESP_HAS_SELECT */
|
||||
static inline int ioctlsocket(int s,long cmd,void *argp)
|
||||
{ return lwip_ioctl(s,cmd,argp); }
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <sys/fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/select.h>
|
||||
#include "esp_task.h"
|
||||
#include "esp_system.h"
|
||||
#include "sdkconfig.h"
|
||||
|
@ -730,6 +731,7 @@
|
|||
#define ESP_DHCP_TIMER 1
|
||||
#define ESP_LWIP_LOGI(...) ESP_LOGI("lwip", __VA_ARGS__)
|
||||
#define ESP_PING 1
|
||||
#define ESP_HAS_SELECT 1
|
||||
|
||||
#if CONFIG_LWIP_IRAM_OPTIMIZATION
|
||||
#define ESP_IRAM_ATTR IRAM_ATTR
|
||||
|
|
|
@ -33,6 +33,24 @@ typedef struct {
|
|||
|
||||
static const char message[] = "Hello world!";
|
||||
|
||||
static int open_dummy_socket()
|
||||
{
|
||||
const struct addrinfo hints = {
|
||||
.ai_family = AF_INET,
|
||||
.ai_socktype = SOCK_DGRAM,
|
||||
};
|
||||
struct addrinfo *res = NULL;
|
||||
|
||||
const int err = getaddrinfo("localhost", "80", &hints, &res);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
TEST_ASSERT_NOT_NULL(res);
|
||||
|
||||
const int dummy_socket_fd = socket(res->ai_family, res->ai_socktype, 0);
|
||||
TEST_ASSERT(dummy_socket_fd >= 0);
|
||||
|
||||
return dummy_socket_fd;
|
||||
}
|
||||
|
||||
static int socket_init()
|
||||
{
|
||||
const struct addrinfo hints = {
|
||||
|
@ -185,11 +203,13 @@ TEST_CASE("socket can do select()", "[vfs]")
|
|||
char recv_message[sizeof(message)];
|
||||
|
||||
init(&uart_fd, &socket_fd);
|
||||
const int dummy_socket_fd = open_dummy_socket();
|
||||
|
||||
fd_set rfds;
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(uart_fd, &rfds);
|
||||
FD_SET(socket_fd, &rfds);
|
||||
FD_SET(dummy_socket_fd, &rfds);
|
||||
|
||||
const test_task_param_t test_task_param = {
|
||||
.fd = socket_fd,
|
||||
|
@ -199,9 +219,10 @@ TEST_CASE("socket can do select()", "[vfs]")
|
|||
TEST_ASSERT_NOT_NULL(test_task_param.sem);
|
||||
start_task(&test_task_param);
|
||||
|
||||
const int s = select(MAX(uart_fd, socket_fd) + 1, &rfds, NULL, NULL, &tv);
|
||||
TEST_ASSERT_EQUAL(s, 1);
|
||||
const int s = select(MAX(MAX(uart_fd, socket_fd), dummy_socket_fd) + 1, &rfds, NULL, NULL, &tv);
|
||||
TEST_ASSERT_EQUAL(1, s);
|
||||
TEST_ASSERT_UNLESS(FD_ISSET(uart_fd, &rfds));
|
||||
TEST_ASSERT_UNLESS(FD_ISSET(dummy_socket_fd, &rfds));
|
||||
TEST_ASSERT(FD_ISSET(socket_fd, &rfds));
|
||||
|
||||
int read_bytes = read(socket_fd, recv_message, sizeof(message));
|
||||
|
@ -212,6 +233,7 @@ TEST_CASE("socket can do select()", "[vfs]")
|
|||
vSemaphoreDelete(test_task_param.sem);
|
||||
|
||||
deinit(uart_fd, socket_fd);
|
||||
close(dummy_socket_fd);
|
||||
}
|
||||
|
||||
TEST_CASE("select() timeout", "[vfs]")
|
||||
|
|
|
@ -782,13 +782,15 @@ int esp_vfs_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!socket_select && is_socket_fd) {
|
||||
// no socket_select found yet and the fd is for a socket so take a look
|
||||
if ((readfds && FD_ISSET(fd, readfds)) ||
|
||||
(writefds && FD_ISSET(fd, writefds)) ||
|
||||
(errorfds && FD_ISSET(fd, errorfds))) {
|
||||
const vfs_entry_t *vfs = s_vfs[vfs_index];
|
||||
socket_select = vfs->vfs.socket_select;
|
||||
if (is_socket_fd) {
|
||||
if (!socket_select) {
|
||||
// no socket_select found yet so take a look
|
||||
if ((readfds && FD_ISSET(fd, readfds)) ||
|
||||
(writefds && FD_ISSET(fd, writefds)) ||
|
||||
(errorfds && FD_ISSET(fd, errorfds))) {
|
||||
const vfs_entry_t *vfs = s_vfs[vfs_index];
|
||||
socket_select = vfs->vfs.socket_select;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue