diff options
author | ivan <ivan@13f79535-47bb-0310-9956-ffa450edef68> | 2019-09-20 13:24:56 +0000 |
---|---|---|
committer | ivan <ivan@13f79535-47bb-0310-9956-ffa450edef68> | 2019-09-20 13:24:56 +0000 |
commit | aa126532877acb3bf3d44ca4898e6f7a6fb6bd5f (patch) | |
tree | 8cfa69edf125d3e3236ae085c08acdf96e624fab /network_io | |
parent | a0f51244e7d21b358e9f96ce5172641b5402694b (diff) | |
download | libapr-aa126532877acb3bf3d44ca4898e6f7a6fb6bd5f.tar.gz |
Remove the APR_SENDFILE_DISCONNECT_SOCKET flag.
There are several problems with this flag:
1. The TCP socket may be subject to the TCP TIME_WAIT state.
That means apr_sock_sendfile() could occupy worker thread
for significant time (30 seconds)
2. With this flag specified, the socket descriptor is removed from the
apr_socket_t and the caller caller is expected to maintain the descriptor
and release it manually, which is particularly error-prone.
See also:
https://lists.apache.org/thread.html/a3c4a03961a4b5842e7f657a15fe777edf5949b768a2807619a104b1@%3Cdev.apr.apache.org%3E
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@1867226 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'network_io')
-rw-r--r-- | network_io/win32/sendrecv.c | 47 |
1 files changed, 13 insertions, 34 deletions
diff --git a/network_io/win32/sendrecv.c b/network_io/win32/sendrecv.c index a841d222d..ccae8c6a2 100644 --- a/network_io/win32/sendrecv.c +++ b/network_io/win32/sendrecv.c @@ -267,7 +267,6 @@ APR_DECLARE(apr_status_t) apr_socket_sendfile(apr_socket_t *sock, apr_size_t nbytes; TRANSMIT_FILE_BUFFERS tfb, *ptfb = NULL; apr_size_t bytes_to_send; /* Bytes to send out of the file (not including headers) */ - int disconnected = 0; int sendv_trailers = 0; char hdtrbuf[4096]; LPFN_TRANSMITFILE pfn_transmit_file = NULL; @@ -388,13 +387,6 @@ APR_DECLARE(apr_status_t) apr_socket_sendfile(apr_socket_t *sock, sendv_trailers = 1; } } - /* Disconnect the socket after last send */ - if ((flags & APR_SENDFILE_DISCONNECT_SOCKET) - && !sendv_trailers) { - dwFlags |= TF_REUSE_SOCKET; - dwFlags |= TF_DISCONNECT; - disconnected = 1; - } } sock->overlapped->Offset = (DWORD)(curoff); @@ -419,21 +411,19 @@ APR_DECLARE(apr_status_t) apr_socket_sendfile(apr_socket_t *sock, ? sock->timeout_ms : INFINITE)); if (rv == WAIT_OBJECT_0) { status = APR_SUCCESS; - if (!disconnected) { - if (!WSAGetOverlappedResult(sock->socketdes, - sock->overlapped, - &xmitbytes, - FALSE, - &dwFlags)) { - status = apr_get_netos_error(); - } - /* Ugly code alert: WSAGetOverlappedResult returns - * a count of all bytes sent. This loop only - * tracks bytes sent out of the file. - */ - else if (ptfb) { - xmitbytes -= (ptfb->HeadLength + ptfb->TailLength); - } + if (!WSAGetOverlappedResult(sock->socketdes, + sock->overlapped, + &xmitbytes, + FALSE, + &dwFlags)) { + status = apr_get_netos_error(); + } + /* Ugly code alert: WSAGetOverlappedResult returns + * a count of all bytes sent. This loop only + * tracks bytes sent out of the file. + */ + else if (ptfb) { + xmitbytes -= (ptfb->HeadLength + ptfb->TailLength); } } else if (rv == WAIT_TIMEOUT) { @@ -473,17 +463,6 @@ APR_DECLARE(apr_status_t) apr_socket_sendfile(apr_socket_t *sock, return rv; *len += nbytes; } - - - /* Mark the socket as disconnected, but do not close it. - * Note: The application must have stored the socket prior to making - * the call to apr_socket_sendfile in order to either reuse it - * or close it. - */ - if (disconnected) { - sock->disconnected = 1; - sock->socketdes = INVALID_SOCKET; - } } return status; |