Skip to content

Commit efe631f

Browse files
Wrap WSAPoll in a function
Instead of using a macro, which breaks when the implementation is compiled separately, add a detail::poll() function, that dispatches to either ::poll() or WSAPoll().
1 parent 045e14f commit efe631f

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

httplib.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ using ssize_t = long;
194194

195195
using socket_t = SOCKET;
196196
using socklen_t = int;
197-
#define poll(fds, nfds, timeout) WSAPoll(fds, nfds, timeout)
198197

199198
#else // not _WIN32
200199

@@ -3240,6 +3239,14 @@ inline ssize_t send_socket(socket_t sock, const void *ptr, size_t size,
32403239
});
32413240
}
32423241

3242+
inline int poll(struct pollfd *fds, nfds_t nfds, int timeout) {
3243+
#ifdef _WIN32
3244+
return WSAPoll(fds, nfds, timeout);
3245+
#else
3246+
return ::poll(fds, nfds, timeout);
3247+
#endif
3248+
}
3249+
32433250
template <bool Read>
32443251
inline ssize_t select_impl(socket_t sock, time_t sec, time_t usec) {
32453252
struct pollfd pfd;
@@ -10377,8 +10384,4 @@ inline SSL_CTX *Client::ssl_context() const {
1037710384

1037810385
} // namespace httplib
1037910386

10380-
#ifdef _WIN32
10381-
#undef poll
10382-
#endif
10383-
1038410387
#endif // CPPHTTPLIB_HTTPLIB_H

0 commit comments

Comments
 (0)