Skip to content

Commit

Permalink
Merge branch 'main' into prometheus-exporter-failure
Browse files Browse the repository at this point in the history
  • Loading branch information
esigo committed Jun 21, 2022
2 parents 17fe7c2 + 5c8f476 commit 6440301
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmake/nlohmann-json.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
"$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_DIR}>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# include <io.h>
# include <winsock2.h>
#else
# include <poll.h>
# include <unistd.h>
#endif
#include <curl/curl.h>
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit 6440301

Please sign in to comment.