Skip to content

Commit 27435b7

Browse files
committed
feat(asio): Drop esp/asio patches in favor of sock-utils
1 parent 813331f commit 27435b7

File tree

10 files changed

+57
-19
lines changed

10 files changed

+57
-19
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[submodule "components/asio/asio"]
22
path = components/asio/asio
3-
url = https://github.com/espressif/asio
3+
url = https://github.com/chriskohlhoff/asio
44
[submodule "components/mosquitto/mosquitto"]
55
path = components/mosquitto/mosquitto
66
url = https://github.com/eclipse/mosquitto

components/asio/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ if(NOT CONFIG_LWIP_IPV6 AND NOT CMAKE_BUILD_EARLY_EXPANSION)
66
return()
77
endif()
88

9-
set(asio_sources "asio/asio/src/asio.cpp")
10-
set(asio_requires lwip)
9+
set(asio_sources "asio/asio/src/asio.cpp" "port/src/asio_stub.cpp")
10+
set(asio_requires lwip sock_utils)
1111

1212
if(CONFIG_ASIO_SSL_SUPPORT)
1313
list(APPEND asio_sources
@@ -18,7 +18,7 @@ if(CONFIG_ASIO_SSL_SUPPORT)
1818
endif()
1919

2020
idf_component_register(SRCS ${asio_sources}
21-
INCLUDE_DIRS "asio/asio/include" "port/include"
21+
INCLUDE_DIRS "port/include" "asio/asio/include"
2222
PRIV_INCLUDE_DIRS ${asio_priv_includes}
2323
PRIV_REQUIRES ${asio_requires})
2424

@@ -30,6 +30,7 @@ target_compile_definitions(${COMPONENT_LIB} PUBLIC SA_RESTART=0x01
3030
ASIO_STANDALONE
3131
ASIO_HAS_PTHREADS
3232
OPENSSL_NO_ENGINE
33+
ASIO_DETAIL_IMPL_POSIX_EVENT_IPP # this replaces asio's posix_event constructor
3334
)
3435

3536
if(NOT CONFIG_COMPILER_CXX_EXCEPTIONS)

components/asio/idf_component.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ repository: https://github.com/espressif/esp-protocols.git
77
dependencies:
88
idf:
99
version: ">=5.0"
10+
espressif/sock_utils:
11+
version: "^0.1"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
// SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
//
4+
// SPDX-License-Identifier: BSL-1.0
5+
//
6+
#pragma once
7+
8+
#include "sys/socket.h"
9+
#include "socketpair.h"
10+
11+
#include_next "asio/detail/config.hpp"

components/asio/port/include/esp_asio_config.h

Lines changed: 0 additions & 12 deletions
This file was deleted.

components/asio/port/mbedtls/src/mbedtls_context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//
99

1010
#include "asio/detail/config.hpp"
11-
#include "openssl_stub.hpp"
11+
#include "asio/ssl/detail/openssl_types.hpp"
1212
#include <cstring>
1313
#include "asio/detail/throw_error.hpp"
1414
#include "asio/error.hpp"

components/asio/port/mbedtls/src/mbedtls_engine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
#include "asio/detail/config.hpp"
10-
#include "openssl_stub.hpp"
10+
#include "asio/ssl/detail/openssl_types.hpp"
1111
#include "asio/detail/throw_error.hpp"
1212
#include "asio/error.hpp"
1313
#include "asio/ssl/detail/engine.hpp"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// SPDX-FileCopyrightText: 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
3+
//
4+
// SPDX-License-Identifier: BSL-1.0
5+
//
6+
// SPDX-FileContributor: 2024 Espressif Systems (Shanghai) CO LTD
7+
//
8+
#include "asio/detail/posix_event.hpp"
9+
#include "asio/detail/throw_error.hpp"
10+
#include "asio/error.hpp"
11+
#include "asio/detail/push_options.hpp"
12+
#include <unistd.h>
13+
#include <climits>
14+
15+
namespace asio::detail {
16+
// This replaces asio's posix_event constructor
17+
// since the default POSIX version uses pthread_condattr_t operations (init, setclock, destroy),
18+
// which are not available on all IDF versions (some are defined in compilers' headers, others in
19+
// pthread library, but they typically return `ENOSYS` which causes trouble in the event wrapper)
20+
// IMPORTANT: Check implementation of posix_event() when upgrading upstream asio in order not to
21+
// miss any initialization step.
22+
posix_event::posix_event()
23+
: state_(0)
24+
{
25+
int error = ::pthread_cond_init(&cond_, nullptr);
26+
asio::error_code ec(error, asio::error::get_system_category());
27+
asio::detail::throw_error(ec, "event");
28+
}
29+
} // namespace asio::detail
30+
31+
extern "C" int pause (void)
32+
{
33+
while (true) {
34+
::sleep(UINT_MAX);
35+
}
36+
}

0 commit comments

Comments
 (0)