summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2023-02-17 06:54:54 -0500
committerGlenn Strauss <gstrauss@gluelogic.com>2023-05-03 23:11:34 -0400
commit6a4cf9400f57542095386484fbdd5f3dd41f8c21 (patch)
tree455c11b750840ffbb245ddfe75971439da744846
parent353b216d95119188d1d1dbe8a0c40b1bd9cb29d9 (diff)
downloadlighttpd-git-6a4cf9400f57542095386484fbdd5f3dd41f8c21.tar.gz
[core] _WIN32 use WSASend for writev-equiv on sock
https://learn.microsoft.com/en-us/windows/win32/winsock/scatter-gather-i-o-2
-rw-r--r--src/network_write.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/network_write.c b/src/network_write.c
index 07aee803..6266877c 100644
--- a/src/network_write.c
+++ b/src/network_write.c
@@ -73,6 +73,9 @@
#if defined HAVE_SYS_UIO_H && defined HAVE_WRITEV
# define NETWORK_WRITE_USE_WRITEV
#endif
+#ifdef _WIN32
+# define NETWORK_WRITE_USE_WRITEV
+#endif
#if defined(HAVE_MMAP) || defined(_WIN32) /*(see local sys-mmap.h)*/
#ifdef ENABLE_MMAP
@@ -234,6 +237,8 @@ static int network_write_file_chunk_mmap(const int fd, chunkqueue * const cq, of
#elif defined(_XOPEN_IOV_MAX)
/* minimum value for sysconf(_SC_IOV_MAX); posix requires this to be at least 16, which is good enough - no need to call sysconf() */
# define SYS_MAX_CHUNKS _XOPEN_IOV_MAX
+#elif defined(_WIN32)
+# define SYS_MAX_CHUNKS 32
#else
# error neither UIO_MAXIOV nor IOV_MAX nor _XOPEN_IOV_MAX are defined
#endif
@@ -249,6 +254,13 @@ static int network_write_file_chunk_mmap(const int fd, chunkqueue * const cq, of
# define MAX_CHUNKS SYS_MAX_CHUNKS
#endif
+#ifdef _WIN32
+/* rewrite iov to WSABUF */
+#define iovec _WSABUF
+#define iov_len len
+#define iov_base buf
+#endif
+
/* next chunk must be MEM_CHUNK. send multiple mem chunks using writev() */
static int network_writev_mem_chunks(const int fd, chunkqueue * const cq, off_t * const p_max_bytes, log_error_st * const errh) {
size_t num_chunks = 0;
@@ -270,7 +282,13 @@ static int network_writev_mem_chunks(const int fd, chunkqueue * const cq, off_t
}
if (0 == num_chunks) return network_remove_finished_chunks(cq, 0);
+ #ifdef _WIN32
+ DWORD dw;
+ ssize_t wr = WSASend(fd, chunks, num_chunks, &dw, 0, NULL, NULL);
+ if (0 == wr) wr = (ssize_t)dw;
+ #else
ssize_t wr = writev(fd, chunks, num_chunks);
+ #endif
return network_write_accounting(fd, cq, p_max_bytes, errh, wr, toSend);
}