diff options
author | Yann Ylavic <ylavic@apache.org> | 2021-11-19 13:23:11 +0000 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2021-11-19 13:23:11 +0000 |
commit | f046eb53d726c944b6ab72acfb97c1c13797f299 (patch) | |
tree | bb76224ec5059fe41df92be49527f66a5ddd355b /network_io | |
parent | 1f24f3cb2a6b170cd694f72e21df25d271b9f0f2 (diff) | |
download | apr-f046eb53d726c944b6ab72acfb97c1c13797f299.tar.gz |
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
Diffstat (limited to 'network_io')
-rw-r--r-- | network_io/os2/sockopt.c | 16 |
1 files changed, 15 insertions, 1 deletions
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; } |