From f046eb53d726c944b6ab72acfb97c1c13797f299 Mon Sep 17 00:00:00 2001 From: Yann Ylavic Date: Fri, 19 Nov 2021 13:23:11 +0000 Subject: Follow up to r1895106: Use less expensive atomics for wakeup. If pipe writers (wakeup) put a single byte until consume it's consumed by the reader (drain), an atomic cas for the writers (still) and an atomic (re)set for the reader is enough (not need to cas on the reader side). This requires that the reader never blocks on read though (e.g. spurious return from poll), so (re)make the read side on the pipe non-blocking (finally). Since synchronous non-blocking read is not a thing for Windows' Readfile(), add a ->socket flag this arch's to apr_file_t (like the existing ->pipe one) which file_socket_pipe_create() will set to make apr_file_read/write() handle non-blocking (nor overlapped) socket pipes with WSARecv/Send(). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1895175 13f79535-47bb-0310-9956-ffa450edef68 --- network_io/os2/sockopt.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'network_io') diff --git a/network_io/os2/sockopt.c b/network_io/os2/sockopt.c index 2ada4fc47..0cce8d78e 100644 --- a/network_io/os2/sockopt.c +++ b/network_io/os2/sockopt.c @@ -32,8 +32,22 @@ APR_DECLARE(apr_status_t) apr_socket_timeout_set(apr_socket_t *sock, apr_interval_time_t t) { + apr_status_t rv = APR_SUCCESS; + + /* If our new timeout is non-negative and our old timeout was + * negative, then we need to ensure that we are non-blocking. + * Conversely, if our new timeout is negative and we had + * non-negative timeout, we must make sure our socket is blocking. + */ + if (t == 0 && sock->timeout != 0) { + rv = apr_socket_opt_set(sock, APR_SO_NONBLOCK, 1); + } + else if (t != 0 && sock->timeout == 0) { + rv = apr_socket_opt_set(sock, APR_SO_NONBLOCK, 0); + } + sock->timeout = t; - return APR_SUCCESS; + return rv; } -- cgit v1.2.1