Skip to content

Commit dcf51c4

Browse files
Run tests with select() and poll()
1 parent e0e7ebc commit dcf51c4

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

.github/workflows/test.yaml

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,21 @@ jobs:
3131
(github.event_name == 'pull_request' &&
3232
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
3333
(github.event_name == 'workflow_dispatch' && github.event.inputs.test_linux == 'true')
34+
strategy:
35+
matrix:
36+
select_impl: ['select', 'poll']
3437
steps:
3538
- name: checkout
3639
uses: actions/checkout@v4
3740
- name: install libraries
3841
run: sudo apt-get update && sudo apt-get install -y libbrotli-dev libcurl4-openssl-dev
3942
- name: build and run tests
43+
env:
44+
SELECT_IMPL: ${{ matrix.select_impl }}
4045
run: cd test && make
4146
- name: run fuzz test target
47+
env:
48+
SELECT_IMPL: ${{ matrix.select_impl }}
4249
run: cd test && make fuzz_test
4350

4451
macos:
@@ -48,12 +55,19 @@ jobs:
4855
(github.event_name == 'pull_request' &&
4956
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
5057
(github.event_name == 'workflow_dispatch' && github.event.inputs.test_macos == 'true')
58+
strategy:
59+
matrix:
60+
select_impl: ['select', 'poll']
5161
steps:
5262
- name: checkout
5363
uses: actions/checkout@v4
5464
- name: build and run tests
65+
env:
66+
SELECT_IMPL: ${{ matrix.select_impl }}
5567
run: cd test && make
5668
- name: run fuzz test target
69+
env:
70+
SELECT_IMPL: ${{ matrix.select_impl }}
5771
run: cd test && make fuzz_test
5872

5973
windows:
@@ -63,6 +77,9 @@ jobs:
6377
(github.event_name == 'pull_request' &&
6478
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
6579
(github.event_name == 'workflow_dispatch' && github.event.inputs.test_windows == 'true')
80+
strategy:
81+
matrix:
82+
select_impl: ['select', 'poll']
6683
steps:
6784
- name: Prepare Git for Checkout on Windows
6885
run: |
@@ -84,14 +101,30 @@ jobs:
84101
choco install openssl
85102
86103
- name: Configure CMake with SSL
87-
run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL=ON -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON
104+
run: >
105+
cmake -B build -S .
106+
-DCMAKE_BUILD_TYPE=Release
107+
-DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake
108+
-DHTTPLIB_TEST=ON
109+
-DHTTPLIB_REQUIRE_OPENSSL=ON
110+
-DHTTPLIB_REQUIRE_ZLIB=ON
111+
-DHTTPLIB_REQUIRE_BROTLI=ON
112+
-DHTTPLIB_USE_SELECT=${{ matrix.select_impl == 'select' ? 'ON' : 'OFF' }}
88113
- name: Build with with SSL
89114
run: cmake --build build --config Release
90115
- name: Run tests with SSL
91116
run: ctest --output-on-failure --test-dir build -C Release
92117

93118
- name: Configure CMake without SSL
94-
run: cmake -B build-no-ssl -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL=OFF -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON
119+
run: >
120+
cmake -B build-no-ssl -S .
121+
-DCMAKE_BUILD_TYPE=Release
122+
-DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake
123+
-DHTTPLIB_TEST=ON
124+
-DHTTPLIB_REQUIRE_OPENSSL=OFF
125+
-DHTTPLIB_REQUIRE_ZLIB=ON
126+
-DHTTPLIB_REQUIRE_BROTLI=ON
127+
-DHTTPLIB_USE_SELECT=${{ matrix.select_impl == 'select' ? 'ON' : 'OFF' }}
95128
- name: Build without SSL
96129
run: cmake --build build-no-ssl --config Release
97130
- name: Run tests without SSL

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* HTTPLIB_REQUIRE_ZLIB (default off)
99
* HTTPLIB_REQUIRE_BROTLI (default off)
1010
* HTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN (default on)
11+
* HTTPLIB_USE_SELECT (default off) choose between select() and poll()
1112
* HTTPLIB_COMPILE (default off)
1213
* HTTPLIB_INSTALL (default on)
1314
* HTTPLIB_TEST (default off)
@@ -46,6 +47,7 @@
4647
* HTTPLIB_IS_USING_ZLIB - a bool for if ZLIB support is enabled.
4748
* HTTPLIB_IS_USING_BROTLI - a bool for if Brotli support is enabled.
4849
* HTTPLIB_IS_USING_CERTS_FROM_MACOSX_KEYCHAIN - a bool for if support of loading system certs from the Apple Keychain is enabled.
50+
* HTTPLIB_IS_USING_SELECT - a bool for if select() is used instead of poll().
4951
* HTTPLIB_IS_COMPILED - a bool for if the library is compiled, or otherwise header-only.
5052
* HTTPLIB_INCLUDE_DIR - the root path to httplib's header (e.g. /usr/include).
5153
* HTTPLIB_LIBRARY - the full path to the library if compiled (e.g. /usr/lib/libhttplib.so).
@@ -101,6 +103,7 @@ option(HTTPLIB_TEST "Enables testing and builds tests" OFF)
101103
option(HTTPLIB_REQUIRE_BROTLI "Requires Brotli to be found & linked, or fails build." OFF)
102104
option(HTTPLIB_USE_BROTLI_IF_AVAILABLE "Uses Brotli (if available) to enable Brotli decompression support." ON)
103105
option(HTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN "Enable feature to load system certs from the Apple Keychain." ON)
106+
option(HTTPLIB_USE_SELECT "Uses select() instead of poll()." OFF)
104107
# Defaults to static library
105108
option(BUILD_SHARED_LIBS "Build the library as a shared library instead of static. Has no effect if using header-only." OFF)
106109
if (BUILD_SHARED_LIBS AND WIN32 AND HTTPLIB_COMPILE)
@@ -112,6 +115,7 @@ endif()
112115
# Set some variables that are used in-tree and while building based on our options
113116
set(HTTPLIB_IS_COMPILED ${HTTPLIB_COMPILE})
114117
set(HTTPLIB_IS_USING_CERTS_FROM_MACOSX_KEYCHAIN ${HTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN})
118+
set(HTTPLIB_IS_USING_SELECT ${HTTPLIB_USE_SELECT})
115119

116120
# Threads needed for <thread> on some systems, and for <pthread.h> on Linux
117121
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
@@ -238,6 +242,7 @@ target_compile_definitions(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
238242
$<$<BOOL:${HTTPLIB_IS_USING_ZLIB}>:CPPHTTPLIB_ZLIB_SUPPORT>
239243
$<$<BOOL:${HTTPLIB_IS_USING_OPENSSL}>:CPPHTTPLIB_OPENSSL_SUPPORT>
240244
$<$<AND:$<PLATFORM_ID:Darwin>,$<BOOL:${HTTPLIB_IS_USING_OPENSSL}>,$<BOOL:${HTTPLIB_IS_USING_CERTS_FROM_MACOSX_KEYCHAIN}>>:CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN>
245+
$<$<BOOL:${HTTPLIB_IS_USING_SELECT}>:CPPHTTPLIB_USE_SELECT>
241246
)
242247

243248
# CMake configuration files installation directory

test/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
CXX = clang++
22
CXXFLAGS = -g -std=c++11 -I. -Wall -Wextra -Wtype-limits -Wconversion -Wshadow # -fno-exceptions -DCPPHTTPLIB_NO_EXCEPTIONS -fsanitize=address
33

4+
ifeq ($(SELECT_IMPL),select)
5+
CXXFLAGS += -DCPPHTTPLIB_USE_SELECT
6+
endif
7+
48
PREFIX ?= $(shell brew --prefix)
59

610
OPENSSL_DIR = $(PREFIX)/opt/openssl@3

0 commit comments

Comments
 (0)