| 30 | // A wrapper for the TransmitFile overlapped I/O operation. |
| 31 | template <typename Handler> |
| 32 | void transmit_file(tcp_socket& socket, |
| 33 | random_access_handle& file, Handler handler) |
| 34 | { |
| 35 | // Construct an OVERLAPPED-derived object to contain the handler. |
| 36 | overlapped_ptr overlapped(socket.get_executor().context(), handler); |
| 37 | |
| 38 | // Initiate the TransmitFile operation. |
| 39 | BOOL ok = ::TransmitFile(socket.native_handle(), |
| 40 | file.native_handle(), 0, 0, overlapped.get(), 0, 0); |
| 41 | DWORD last_error = ::GetLastError(); |
| 42 | |
| 43 | // Check if the operation completed immediately. |
| 44 | if (!ok && last_error != ERROR_IO_PENDING) |
| 45 | { |
| 46 | // The operation completed immediately, so a completion notification needs |
| 47 | // to be posted. When complete() is called, ownership of the OVERLAPPED- |
| 48 | // derived object passes to the io_context. |
| 49 | boost::system::error_code ec(last_error, |
| 50 | boost::asio::error::get_system_category()); |
| 51 | overlapped.complete(ec, 0); |
| 52 | } |
| 53 | else |
| 54 | { |
| 55 | // The operation was successfully initiated, so ownership of the |
| 56 | // OVERLAPPED-derived object has passed to the io_context. |
| 57 | overlapped.release(); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | class connection |
| 62 | : public std::enable_shared_from_this<connection> |
no test coverage detected