|
19 | 19 | #ifdef _WIN32 |
20 | 20 | #define _CRT_SECURE_NO_WARNINGS |
21 | 21 | #define strcasecmp _stricmp |
| 22 | + #define strncasecmp _strnicmp |
22 | 23 | #define strdup _strdup |
23 | 24 | #define close closesocket |
24 | 25 | #define ssize_t SSIZE_T |
25 | 26 | /* Helper for snprintf size parameter (Windows uses int, POSIX uses size_t) */ |
26 | 27 | #define SNPRINTF_SIZE(size) ((int)(size)) |
| 28 | + /* Windows select() ignores first parameter (nfds) */ |
| 29 | + #define SELECT_NFDS(sockfd) 0 |
27 | 30 | #else |
28 | 31 | #define SNPRINTF_SIZE(size) (size) |
| 32 | + /* POSIX select() needs nfds = highest fd + 1 */ |
| 33 | + #define SELECT_NFDS(sockfd) ((sockfd) + 1) |
29 | 34 | #endif |
30 | 35 |
|
31 | 36 | #include "../include/httpmorph.h" |
@@ -778,7 +783,7 @@ static int tcp_connect(const char *host, uint16_t port, uint32_t timeout_ms, |
778 | 783 | tv.tv_sec = timeout_ms / 1000; |
779 | 784 | tv.tv_usec = (timeout_ms % 1000) * 1000; |
780 | 785 |
|
781 | | - ret = select(sockfd + 1, NULL, &write_fds, NULL, &tv); |
| 786 | + ret = select(SELECT_NFDS(sockfd), NULL, &write_fds, NULL, &tv); |
782 | 787 | if (ret > 0) { |
783 | 788 | /* Check if connection succeeded */ |
784 | 789 | int error = 0; |
@@ -1593,7 +1598,7 @@ static int http2_request(SSL *ssl, const httpmorph_request_t *request, |
1593 | 1598 | tv.tv_sec = 5; /* 5 second timeout */ |
1594 | 1599 | tv.tv_usec = 0; |
1595 | 1600 |
|
1596 | | - int select_rv = select(sockfd + 1, &readfds, &writefds, NULL, &tv); |
| 1601 | + int select_rv = select(SELECT_NFDS(sockfd), &readfds, &writefds, NULL, &tv); |
1597 | 1602 | if (select_rv < 0) { |
1598 | 1603 | /* Error */ |
1599 | 1604 | rv = -1; |
|
0 commit comments