Files
MINGW-packages/mingw-w64-h2o/0010-more-socket-work-for-windows-on-evloop.patch
2015-06-27 12:35:34 +01:00

106 lines
3.3 KiB
Diff

From 4227b19fd8fa974c7c59431974c92e318a3758b8 Mon Sep 17 00:00:00 2001
From: Martell Malone <martellmalone@gmail.com>
Date: Sat, 27 Jun 2015 12:30:40 +0100
Subject: [PATCH 2/2] more socket work for windows on evloop
diff --git a/include/h2o/socket.h b/include/h2o/socket.h
index 42cd530..5f3b6ef 100644
--- a/include/h2o/socket.h
+++ b/include/h2o/socket.h
@@ -43,10 +43,10 @@ extern "C" {
#endif
#endif
-#if OPENSSL_VERSION_NUMBER >= 0x10002000L
+#if OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(_WIN32)
#define H2O_USE_ALPN 1
#define H2O_USE_NPN 1
-#elif OPENSSL_VERSION_NUMBER >= 0x10001000L
+#elif OPENSSL_VERSION_NUMBER >= 0x10001000L && !defined(_WIN32)
#define H2O_USE_ALPN 0
#define H2O_USE_NPN 1
#else
diff --git a/lib/common/socket/evloop.c.h b/lib/common/socket/evloop.c.h
index fb859e1..899b16f 100644
--- a/lib/common/socket/evloop.c.h
+++ b/lib/common/socket/evloop.c.h
@@ -44,7 +44,28 @@ writev(SOCKET fd, const struct iovec *iov, int iovcnt) {
return -1;
}
+# undef socket_error
+# undef read_socket
+# undef close_socket
+# undef EINTR
+# define EINTR WSAEINTR
+# undef EWOULDBLOCK
+# define EWOULDBLOCK WSAEWOULDBLOCK
+# undef EAGAIN
+# define EAGAIN WSAEWOULDBLOCK
+# undef EINPROGRESS
+# define EINPROGRESS WSAEINPROGRESS
+
+# define socket_error WSAGetLastError()
+# define read_socket(f, d, s) recv(f, d, s, 0)
+# define close_socket(f) closesocket(f)
+
#else
+
+# define socket_error errno
+# define read_socket(f, d, s) read(fd, d, s)
+# define close_socket(f) close(f)
+
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
@@ -140,10 +161,10 @@ static int on_read_core(int fd, h2o_buffer_t **input)
/* memory allocation failed */
return -1;
}
- while ((rret = read(fd, buf.base, buf.len)) == -1 && errno == EINTR)
+ while ((rret = read_socket(fd, buf.base, buf.len)) == -1 && socket_error == EINTR)
;
if (rret == -1) {
- if (errno == EAGAIN)
+ if (socket_error == EAGAIN)
break;
else
return -1;
@@ -182,10 +203,10 @@ static int write_core(int fd, h2o_iovec_t **bufs, size_t *bufcnt)
iovcnt = IOV_MAX;
if (*bufcnt < iovcnt)
iovcnt = (int)*bufcnt;
- while ((wret = writev(fd, (struct iovec *)*bufs, iovcnt)) == -1 && errno == EINTR)
+ while ((wret = writev(fd, (struct iovec *)*bufs, iovcnt)) == -1 && socket_error == EINTR)
;
if (wret == -1) {
- if (errno != EAGAIN)
+ if (socket_error != EAGAIN)
return -1;
break;
}
@@ -269,7 +290,7 @@ void do_dispose_socket(h2o_socket_t *_sock)
evloop_do_on_socket_close(sock);
wreq_free_buffer_if_allocated(sock);
if (sock->fd != -1) {
- close(sock->fd);
+ close_socket(sock->fd);
sock->fd = -1;
}
sock->_flags = H2O_SOCKET_FLAG_IS_DISPOSED;
@@ -472,8 +493,8 @@ h2o_socket_t *h2o_socket_connect(h2o_loop_t *loop, struct sockaddr *addr, sockle
fcntl(fd, F_SETFL, O_NONBLOCK);
#endif
- if (!(connect(fd, addr, addrlen) == 0 || errno == EINPROGRESS)) {
- close(fd);
+ if (!(connect(fd, addr, addrlen) == 0 || socket_error == EINPROGRESS)) {
+ close_socket(fd);
return NULL;
}
--
2.4.4