From 0ef9446f7aefaf2ae9852b28c32fc94f075e9578 Mon Sep 17 00:00:00 2001 From: ztao Date: Sat, 21 May 2022 14:16:41 +0800 Subject: [PATCH 1/2] fix: WaitOnSocket select error when sockfd above FD_SETSIZE (#1410) --- .../http/client/curl/http_operation_curl.h | 55 +++++++++++++++++-- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h b/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h index 09cf8c7c2a..679251cfeb 100644 --- a/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h +++ b/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h @@ -17,6 +17,7 @@ # include # include #else +# include # include #endif #include @@ -443,13 +444,19 @@ class HttpOperation * @param sockfd * @param for_recv * @param timeout_ms - * @return + * @return true if expected events occur, false if timeout or error happen */ - static int WaitOnSocket(curl_socket_t sockfd, int for_recv, long timeout_ms) + static bool WaitOnSocket(curl_socket_t sockfd, int for_recv, long timeout_ms) { + bool res = false; + +#if defined(_WIN32) + + if (sockfd > FD_SETSIZE) + return false; + struct timeval tv; fd_set infd, outfd, errfd; - int res; tv.tv_sec = timeout_ms / 1000; tv.tv_usec = (timeout_ms % 1000) * 1000; @@ -470,7 +477,47 @@ class HttpOperation } /* select() returns the number of signalled sockets or -1 */ - res = select((int)sockfd + 1, &infd, &outfd, &errfd, &tv); + if (select((int)sockfd + 1, &infd, &outfd, &errfd, &tv) > 0) + { + if (for_recv) + { + res = (0 != FD_ISSET(sockfd, &infd)); + } + else + { + res = (0 != FD_ISSET(sockfd, &outfd)); + } + } + +#else + + struct pollfd fds[1]; + ::memset(fds, 0, sizeof(fds)); + + fds[0].fd = sockfd; + if (for_recv) + { + fds[0].events = POLLIN; + } + else + { + fds[0].events = POLLOUT; + } + + if (poll(fds, 1, timeout_ms) > 0) + { + if (for_recv) + { + res = (0 != (fds[0].revents & POLLIN)); + } + else + { + res = (0 != (fds[0].revents & POLLOUT)); + } + } + +#endif + return res; } From 5c8f476459d991d8ff8e45e1652d3f835b551d98 Mon Sep 17 00:00:00 2001 From: Leo Di Donato Date: Tue, 24 May 2022 18:26:40 +0200 Subject: [PATCH 2/2] [BUILD] fix nlohmann_json's (third party) include dir (#1415) --- cmake/nlohmann-json.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/nlohmann-json.cmake b/cmake/nlohmann-json.cmake index 7e057ee602..b5b4355e45 100644 --- a/cmake/nlohmann-json.cmake +++ b/cmake/nlohmann-json.cmake @@ -26,7 +26,7 @@ ExternalProject_Add(nlohmann_json_download ) ExternalProject_Get_Property(nlohmann_json_download INSTALL_DIR) -SET(NLOHMANN_JSON_INCLUDE_DIR ${INSTALL_DIR}/third_party/src/nlohmann_json_download/single_include) +SET(NLOHMANN_JSON_INCLUDE_DIR ${INSTALL_DIR}/src/nlohmann_json_download/single_include) add_library(nlohmann_json_ INTERFACE) target_include_directories(nlohmann_json_ INTERFACE "$"