diff options
author | Ivan Zhakov <ivan@apache.org> | 2019-09-14 09:32:03 +0000 |
---|---|---|
committer | Ivan Zhakov <ivan@apache.org> | 2019-09-14 09:32:03 +0000 |
commit | d9e0d024df1501868a5986525669432e8b50c638 (patch) | |
tree | d82096d0c77afa03ee621b7875d0c756f8021eb2 /network_io | |
parent | fa844cac0e095cec551cfb0b1e7cea2d32b2375c (diff) | |
download | apr-d9e0d024df1501868a5986525669432e8b50c638.tar.gz |
win32: Do not use TransmitFile directly. According to documentation
TransmitFile() should not be used directly and pointer to function should
retrieved using WSAIoctl:
https://docs.microsoft.com/en-gb/windows/win32/api/mswsock/nf-mswsock-transmitfile#remarks
* network_io/win32/sendrecv.c
(apr_socket_sendfile): Retrieve pointer to TransmitFile using WSAIoctl.
* CMakeLists.txt
(APR_SYSTEM_LIBS): Remove reference to mswsock.lib.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1866932 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'network_io')
-rw-r--r-- | network_io/win32/sendrecv.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/network_io/win32/sendrecv.c b/network_io/win32/sendrecv.c index 0580e774f..21779082d 100644 --- a/network_io/win32/sendrecv.c +++ b/network_io/win32/sendrecv.c @@ -270,6 +270,24 @@ APR_DECLARE(apr_status_t) apr_socket_sendfile(apr_socket_t *sock, int disconnected = 0; int sendv_trailers = 0; char hdtrbuf[4096]; + LPFN_TRANSMITFILE pfn_transmit_file = NULL; + static GUID wsaid_transmitfile = WSAID_TRANSMITFILE; + DWORD dw; + + /* According to documentation TransmitFile() should not be used directly. + * Pointer to function should retrieved using WSAIoctl: + * https://docs.microsoft.com/en-gb/windows/win32/api/mswsock/nf-mswsock-transmitfile#remarks + */ + if (WSAIoctl(sock->socketdes, SIO_GET_EXTENSION_FUNCTION_POINTER, + &wsaid_transmitfile, sizeof(wsaid_transmitfile), + &pfn_transmit_file, sizeof(pfn_transmit_file), + &dw, NULL, NULL) == SOCKET_ERROR) { + return apr_get_os_error(); + } + + if (dw != sizeof(pfn_transmit_file)) { + return APR_EINVAL; + } /* Use len to keep track of number of total bytes sent (including headers) */ bytes_to_send = *len; @@ -362,13 +380,13 @@ APR_DECLARE(apr_status_t) apr_socket_sendfile(apr_socket_t *sock, sock->overlapped->OffsetHigh = (DWORD)(curoff >> 32); #endif /* XXX BoundsChecker claims dwFlags must not be zero. */ - rv = TransmitFile(sock->socketdes, /* socket */ - file->filehand, /* open file descriptor of the file to be sent */ - xmitbytes, /* number of bytes to send. 0=send all */ - 0, /* Number of bytes per send. 0=use default */ - sock->overlapped, /* OVERLAPPED structure */ - ptfb, /* header and trailer buffers */ - dwFlags); /* flags to control various aspects of TransmitFile */ + rv = pfn_transmit_file(sock->socketdes, /* socket */ + file->filehand, /* open file descriptor of the file to be sent */ + xmitbytes, /* number of bytes to send. 0=send all */ + 0, /* Number of bytes per send. 0=use default */ + sock->overlapped, /* OVERLAPPED structure */ + ptfb, /* header and trailer buffers */ + dwFlags); /* flags to control various aspects of TransmitFile */ if (!rv) { status = apr_get_netos_error(); if ((status == APR_FROM_OS_ERROR(ERROR_IO_PENDING)) || |