diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2020-11-26 15:17:02 -0500 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2023-05-03 23:11:34 -0400 |
commit | abaf0a5f4d17206340f54420558fc7dfaae62e4f (patch) | |
tree | 10c041f2a1edc46e31424dde903d15b599c9b564 /src/gw_backend.c | |
parent | 9b9dd8efafbf74b173f7d79f791b0736c797900f (diff) | |
download | lighttpd-git-abaf0a5f4d17206340f54420558fc7dfaae62e4f.tar.gz |
[core] _WIN32 socket-compat, filesystem-compat
_WIN32 is sufficiently different -- *different*; not better -- that
isolating _WIN32 code is clearer than #ifdef _WIN32 in almost every
func in fdevent.c
_WIN32-specific fdevent_socket_* funcs
_WIN32 SOCKET fds must be closed with closesocket(), not close()
_WIN32 HANDLE_FLAG_INHERIT for FD_CLOEXEC
_WIN32 use _sopen_s() without _O_TEMPORARY
Use _sopen_s() without _O_TEMPORARY in fdevent_mkostemp().
_O_TEMPORARY would remove file once last handle to file is closed.
Temporary files in chunkqueue may be closed for large request/response
_WIN32 fdevent_rename() using MoveFileExA
_WIN32 rename() fails if the target file already exists.
Alternatives are MoveFileExA() or ReplaceFileA().
Both of the above fail if either oldfile or newfile are open, so
- not atomic
- may fail sporadically
Diffstat (limited to 'src/gw_backend.c')
-rw-r--r-- | src/gw_backend.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/gw_backend.c b/src/gw_backend.c index 2f356b53..e80a7261 100644 --- a/src/gw_backend.c +++ b/src/gw_backend.c @@ -514,7 +514,7 @@ static int gw_spawn_connection(gw_host * const host, gw_proc * const proc, log_e unlink(proc->unixsocket->ptr); } - close(gw_fd); + fdio_close_socket(gw_fd); if (-1 == status) { /* server is not up, spawn it */ @@ -522,7 +522,15 @@ static int gw_spawn_connection(gw_host * const host, gw_proc * const proc, log_e uint32_t i; /* reopen socket */ + + #ifdef _WIN32 + /* Note: not using WSA_FLAG_OVERLAPPED + * because we are assigning to hStdInput of child process */ + gw_fd = WSASocketA(proc->saddr->sa_family, SOCK_STREAM, 0, NULL, 0, + WSA_FLAG_NO_HANDLE_INHERIT); + #else gw_fd = fdevent_socket_cloexec(proc->saddr->sa_family, SOCK_STREAM, 0); + #endif if (-1 == gw_fd) { log_perror(errh, __FILE__, __LINE__, "socket()"); return -1; @@ -530,7 +538,7 @@ static int gw_spawn_connection(gw_host * const host, gw_proc * const proc, log_e if (fdevent_set_so_reuseaddr(gw_fd, 1) < 0) { log_perror(errh, __FILE__, __LINE__, "socketsockopt()"); - close(gw_fd); + fdio_close_socket(gw_fd); return -1; } @@ -538,13 +546,13 @@ static int gw_spawn_connection(gw_host * const host, gw_proc * const proc, log_e if (-1 == bind(gw_fd, proc->saddr, proc->saddrlen)) { log_perror(errh, __FILE__, __LINE__, "bind failed for: %s", proc->connection_name->ptr); - close(gw_fd); + fdio_close_socket(gw_fd); return -1; } if (-1 == listen(gw_fd, host->listen_backlog)) { log_perror(errh, __FILE__, __LINE__, "listen()"); - close(gw_fd); + fdio_close_socket(gw_fd); return -1; } @@ -627,7 +635,7 @@ static int gw_spawn_connection(gw_host * const host, gw_proc * const proc, log_e for (i = 0; i < env.used; ++i) free(env.ptr[i]); free(env.ptr); if (dfd >= 0) close(dfd); - close(gw_fd); + fdio_close_socket(gw_fd); if (-1 == proc->pid) { proc->pid = 0; |