Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,17 @@ jobs:
matrix:
config:
- with_ssl: false
compiled: false
run_tests: true
name: without SSL
- with_ssl: true
compiled: false
run_tests: true
name: with SSL
- with_ssl: false
compiled: true
run_tests: false
name: compiled
name: windows ${{ matrix.config.name }}
steps:
- name: Prepare Git for Checkout on Windows
Expand Down Expand Up @@ -128,12 +136,14 @@ jobs:
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake
-DHTTPLIB_TEST=ON
-DHTTPLIB_COMPILE=${{ matrix.config.compiled && 'ON' || 'OFF' }}
-DHTTPLIB_REQUIRE_ZLIB=ON
-DHTTPLIB_REQUIRE_BROTLI=ON
-DHTTPLIB_REQUIRE_OPENSSL=${{ matrix.config.with_ssl && 'ON' || 'OFF' }}
- name: Build ${{ matrix.config.name }}
run: cmake --build build --config Release -- /v:m /clp:ShowCommandLine
- name: Run tests ${{ matrix.config.name }}
if: ${{ matrix.config.run_tests }}
run: ctest --output-on-failure --test-dir build -C Release

env:
Expand Down
19 changes: 12 additions & 7 deletions httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ using ssize_t = long;
#define WSA_FLAG_NO_HANDLE_INHERIT 0x80
#endif

using nfds_t = unsigned long;
using socket_t = SOCKET;
using socklen_t = int;
#define poll(fds, nfds, timeout) WSAPoll(fds, nfds, timeout)

#else // not _WIN32

Expand Down Expand Up @@ -3240,6 +3240,14 @@ inline ssize_t send_socket(socket_t sock, const void *ptr, size_t size,
});
}

inline int poll_wrapper(struct pollfd *fds, nfds_t nfds, int timeout) {
#ifdef _WIN32
return ::WSAPoll(fds, nfds, timeout);
#else
return ::poll(fds, nfds, timeout);
#endif
}

template <bool Read>
inline ssize_t select_impl(socket_t sock, time_t sec, time_t usec) {
struct pollfd pfd;
Expand All @@ -3248,7 +3256,7 @@ inline ssize_t select_impl(socket_t sock, time_t sec, time_t usec) {

auto timeout = static_cast<int>(sec * 1000 + usec / 1000);

return handle_EINTR([&]() { return poll(&pfd, 1, timeout); });
return handle_EINTR([&]() { return poll_wrapper(&pfd, 1, timeout); });
}

inline ssize_t select_read(socket_t sock, time_t sec, time_t usec) {
Expand All @@ -3267,7 +3275,8 @@ inline Error wait_until_socket_is_ready(socket_t sock, time_t sec,

auto timeout = static_cast<int>(sec * 1000 + usec / 1000);

auto poll_res = handle_EINTR([&]() { return poll(&pfd_read, 1, timeout); });
auto poll_res =
handle_EINTR([&]() { return poll_wrapper(&pfd_read, 1, timeout); });

if (poll_res == 0) { return Error::ConnectionTimeout; }

Expand Down Expand Up @@ -10377,8 +10386,4 @@ inline SSL_CTX *Client::ssl_context() const {

} // namespace httplib

#ifdef _WIN32
#undef poll
#endif

#endif // CPPHTTPLIB_HTTPLIB_H
Loading