Skip to content

Commit 57c8ba9

Browse files
committed
fix: win
1 parent 111afda commit 57c8ba9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/core/httpmorph.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,13 @@ static int tcp_connect(const char *host, uint16_t port, uint32_t timeout_ms,
710710
}
711711

712712
/* Set socket to non-blocking for timeout support */
713+
#ifdef _WIN32
714+
u_long mode = 1;
715+
ioctlsocket(sockfd, FIONBIO, &mode);
716+
#else
713717
int flags = fcntl(sockfd, F_GETFL, 0);
714718
fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
719+
#endif
715720

716721
/* Attempt connection */
717722
ret = connect(sockfd, rp->ai_addr, rp->ai_addrlen);
@@ -751,8 +756,13 @@ static int tcp_connect(const char *host, uint16_t port, uint32_t timeout_ms,
751756

752757
if (sockfd != -1) {
753758
/* Set socket back to blocking mode */
759+
#ifdef _WIN32
760+
u_long mode = 0;
761+
ioctlsocket(sockfd, FIONBIO, &mode);
762+
#else
754763
int flags = fcntl(sockfd, F_GETFL, 0);
755764
fcntl(sockfd, F_SETFL, flags & ~O_NONBLOCK);
765+
#endif
756766

757767
/* Set performance options */
758768
int opt = 1;
@@ -1999,8 +2009,13 @@ httpmorph_response_t* httpmorph_request_execute(
19992009

20002010
/* Set socket to non-blocking for HTTP/2 */
20012011
if (sockfd != -1) {
2012+
#ifdef _WIN32
2013+
u_long mode = 1;
2014+
ioctlsocket(sockfd, FIONBIO, &mode);
2015+
#else
20022016
int flags = fcntl(sockfd, F_GETFL, 0);
20032017
fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
2018+
#endif
20042019
}
20052020
} else if (alpn_len == 8 && memcmp(alpn_data, "http/1.1", 8) == 0) {
20062021
/* HTTP/1.1 negotiated */

0 commit comments

Comments
 (0)