From 13d603e486624380d49f2e89614b10425c208d14 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Thu, 7 Nov 2019 12:07:44 +0100 Subject: [PATCH 1/2] asio: updated ASIO port to use latest asio and esp-idf features closes https://github.com/espressif/esp-idf/issues/4296 --- components/asio/asio | 2 +- .../asio/port/include/esp_asio_config.h | 12 +++++------ components/newlib/pthread.c | 20 +++++++++++++++++- docs/en/api-reference/protocols/asio.rst | 21 +++++++++---------- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/components/asio/asio b/components/asio/asio index 55efc179b..3b66e5b05 160000 --- a/components/asio/asio +++ b/components/asio/asio @@ -1 +1 @@ -Subproject commit 55efc179b76139c8f9b44bf22a4aba4803f7a7bd +Subproject commit 3b66e5b051381fb70de9c2791df70a06181c64e3 diff --git a/components/asio/port/include/esp_asio_config.h b/components/asio/port/include/esp_asio_config.h index f8617fcc9..750f4cbe3 100644 --- a/components/asio/port/include/esp_asio_config.h +++ b/components/asio/port/include/esp_asio_config.h @@ -22,8 +22,12 @@ # define ASIO_NO_EXCEPTIONS # endif // CONFIG_COMPILER_CXX_EXCEPTIONS +# ifndef CONFIG_COMPILER_RTTI +# define ASIO_NO_TYPEID +# endif // CONFIG_COMPILER_RTTI + // -// LWIP compatifility inet and address macros/functions +// LWIP compatibility inet and address macros/functions // # define LWIP_COMPAT_SOCKET_INET 1 # define LWIP_COMPAT_SOCKET_ADDR 1 @@ -34,12 +38,6 @@ # define ASIO_DISABLE_SERIAL_PORT # define ASIO_SEPARATE_COMPILATION # define ASIO_STANDALONE -# define ASIO_NO_TYPEID -# define ASIO_DISABLE_SIGNAL # define ASIO_HAS_PTHREADS -# define ASIO_DISABLE_EPOLL -# define ASIO_DISABLE_EVENTFD -# define ASIO_DISABLE_SIGNAL -# define ASIO_DISABLE_SIGACTION #endif // _ESP_ASIO_CONFIG_H_ diff --git a/components/newlib/pthread.c b/components/newlib/pthread.c index c5bd0c51f..ab921c7e0 100644 --- a/components/newlib/pthread.c +++ b/components/newlib/pthread.c @@ -5,7 +5,7 @@ const static char *TAG = "esp32_asio_pthread"; int pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id) { - ESP_LOGW(TAG, "%s: not yet supported!", __FUNCTION__); + ESP_LOGW(TAG, "%s: not yet supported!", __func__); return 0; } @@ -14,6 +14,24 @@ int pthread_setcancelstate(int state, int *oldstate) return 0; } +// This functions (pthread_sigmask(), sigfillset) are called from ASIO::signal_blocker to temporarily silence signals +// Since signals are not yet supported in ESP pthread these functions serve as no-ops +// +int pthread_sigmask(int how, const sigset_t *restrict set, sigset_t *restrict oset) +{ + ESP_LOGD(TAG, "%s: Signals not supported in ESP pthread", __func__); + return 0; +} + +int sigfillset(sigset_t *what) +{ + ESP_LOGD(TAG, "%s: Signals not supported in ESP pthread", __func__); + if (what != NULL) { + *what = ~0; + } + return 0; +} + void newlib_include_pthread_impl(void) { // Linker hook, exists for no other purpose diff --git a/docs/en/api-reference/protocols/asio.rst b/docs/en/api-reference/protocols/asio.rst index 635ef053f..dcf704131 100644 --- a/docs/en/api-reference/protocols/asio.rst +++ b/docs/en/api-reference/protocols/asio.rst @@ -15,18 +15,17 @@ Supported features ^^^^^^^^^^^^^^^^^^ ESP platform port currently supports only network asynchronous socket operations; does not support serial port and ssl. Internal asio settings for ESP include -- EXCEPTIONS: Supported, choice in menuconfig -- SIGNAL, SIGACTION: Not supported -- EPOLL, EVENTFD: Not supported -- TYPEID: Disabled by default, but supported in toolchain and asio (provided stdlib recompiled with -frtti) + +- EXCEPTIONS are enabled in ASIO if enabled in menuconfig +- TYPEID is enabled in ASIO if enabled in menuconfig Application Example ------------------- -ESP examples are based on standard asio examples `examples/protocols/asio`: -- udp_echo_server -- tcp_echo_server -- chat_client -- chat_server +ESP examples are based on standard asio :example:`examples/protocols/asio`: + +- :example:`examples/protocols/asio/udp_echo_server` +- :example:`examples/protocols/asio/tcp_echo_server` +- :example:`examples/protocols/asio/chat_client` +- :example:`examples/protocols/asio/chat_server` + Please refer to the specific example README.md for details - - From b7ef7feaebf9ad3f532c088ea3bc77021c34a69c Mon Sep 17 00:00:00 2001 From: David Cermak Date: Mon, 9 Dec 2019 16:09:26 +0100 Subject: [PATCH 2/2] newlib: using lwip implementation of interface name/index conversion Links https://github.com/espressif/esp-idf/issues/3557 --- components/newlib/platform_include/net/if.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/newlib/platform_include/net/if.h b/components/newlib/platform_include/net/if.h index e3d0a601a..4a60be477 100644 --- a/components/newlib/platform_include/net/if.h +++ b/components/newlib/platform_include/net/if.h @@ -15,6 +15,7 @@ #define _ESP_PLATFORM_NET_IF_H_ #include "lwip/sockets.h" +#include "lwip/if_api.h" #define MSG_DONTROUTE 0x4 /* send without using routing tables */ #define SOCK_SEQPACKET 5 /* sequenced packet stream */ @@ -22,8 +23,6 @@ #define SOCK_SEQPACKET 5 /* sequenced packet stream */ #define SOMAXCONN 128 -#define IF_NAMESIZE 16 - #define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */ #define NI_MAXHOST 1025