aboutsummaryrefslogtreecommitdiff
path: root/src/os/win32
diff options
context:
space:
mode:
Diffstat (limited to 'src/os/win32')
-rw-r--r--src/os/win32/ngx_init.c9
-rw-r--r--src/os/win32/ngx_recv.c93
-rw-r--r--src/os/win32/ngx_win32_config.h35
3 files changed, 129 insertions, 8 deletions
diff --git a/src/os/win32/ngx_init.c b/src/os/win32/ngx_init.c
index 8c3511fe7..4f356a1c2 100644
--- a/src/os/win32/ngx_init.c
+++ b/src/os/win32/ngx_init.c
@@ -7,17 +7,10 @@ int ngx_max_sockets;
ngx_os_io_t ngx_os_io = {
-#if 0
- ngx_unix_recv,
- NULL,
- NULL,
- ngx_freebsd_write_chain
-#else
- NULL,
+ ngx_wsarecv,
NULL,
NULL,
NULL
-#endif
};
diff --git a/src/os/win32/ngx_recv.c b/src/os/win32/ngx_recv.c
new file mode 100644
index 000000000..ad2232c21
--- /dev/null
+++ b/src/os/win32/ngx_recv.c
@@ -0,0 +1,93 @@
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+#include <ngx_event.h>
+
+
+ssize_t ngx_wsarecv(ngx_connection_t *c, char *buf, size_t size)
+{
+ int rc;
+ u_int flags;
+ size_t bytes;
+ ngx_err_t err;
+ WSABUF wsabuf[1];
+ ngx_event_t *ev;
+ LPWSAOVERLAPPED_COMPLETION_ROUTINE handler;
+
+ ev = c->read;
+
+/* DEBUG */ bytes = 0;
+
+ if (ev->timedout) {
+ ngx_set_socket_errno(NGX_ETIMEDOUT);
+ ngx_log_error(NGX_LOG_ERR, ev->log, 0, "WSARecv() timed out");
+
+ return NGX_ERROR;
+ }
+
+ if (ev->ready) {
+ ev->ready = 0;
+
+#if (HAVE_IOCP_EVENT) /* iocp */
+
+ if (ngx_event_flags & NGX_HAVE_IOCP_EVENT) {
+ if (ev->ovlp.error) {
+ ngx_log_error(NGX_LOG_ERR, c->log, ev->ovlp.error,
+ "WSARecv() failed");
+ return NGX_ERROR;
+ }
+
+ return ev->available;
+ }
+
+#endif
+
+ if (WSAGetOverlappedResult(c->fd, (LPWSAOVERLAPPED) &ev->ovlp,
+ &bytes, 0, NULL) == 0) {
+ err = ngx_socket_errno;
+ ngx_log_error(NGX_LOG_CRIT, ev->log, err,
+ "WSARecv() or WSAGetOverlappedResult() failed");
+
+ return NGX_ERROR;
+ }
+
+ return bytes;
+ }
+
+ ngx_memzero(&ev->ovlp, sizeof(WSAOVERLAPPED));
+ wsabuf[0].buf = buf;
+ wsabuf[0].len = size;
+ flags = 0;
+
+#if 0
+ handler = ev->handler;
+#else
+ handler = NULL;
+#endif
+
+ rc = WSARecv(c->fd, wsabuf, 1, &bytes, &flags,
+ (LPWSAOVERLAPPED) &ev->ovlp, handler);
+
+ ngx_log_debug(ev->log, "WSARecv: %d:%d" _ rc _ bytes);
+
+ if (rc == -1) {
+ err = ngx_socket_errno;
+ if (err == WSA_IO_PENDING) {
+ return NGX_AGAIN;
+
+ } else {
+ ngx_log_error(NGX_LOG_CRIT, ev->log, err, "WSARecv() failed");
+ return NGX_ERROR;
+ }
+ }
+
+#if (HAVE_IOCP_EVENT) /* iocp */
+
+ if (ngx_event_flags & NGX_HAVE_IOCP_EVENT) {
+ return NGX_AGAIN;
+ }
+
+#endif
+
+ return bytes;
+}
diff --git a/src/os/win32/ngx_win32_config.h b/src/os/win32/ngx_win32_config.h
new file mode 100644
index 000000000..1cad3ed47
--- /dev/null
+++ b/src/os/win32/ngx_win32_config.h
@@ -0,0 +1,35 @@
+#ifndef _NGX_WIN32_CONFIG_H_INCLUDED_
+#define _NGX_WIN32_CONFIG_H_INCLUDED_
+
+
+#define WIN32 1
+
+#include <winsock2.h>
+#include <mswsock.h>
+#include <stddef.h> /* offsetof */
+#include <stdio.h>
+#include <stdarg.h>
+
+
+#define ngx_inline __inline
+
+
+#ifndef HAVE_INHERITED_NONBLOCK
+#define HAVE_INHERITED_NONBLOCK 1
+#endif
+
+#ifndef HAVE_WIN32_TRANSMITPACKETS
+#define HAVE_WIN32_TRANSMITPACKETS 1
+#define HAVE_WIN32_TRANSMITFILE 0
+#endif
+
+#ifndef HAVE_WIN32_TRANSMITFILE
+#define HAVE_WIN32_TRANSMITFILE 1
+#endif
+
+#if (HAVE_WIN32_TRANSMITPACKETS) || (HAVE_WIN32_TRANSMITFILE)
+#define HAVE_SENDFILE 1
+#endif
+
+
+#endif /* _NGX_WIN32_CONFIG_H_INCLUDED_ */