MCPcopy Create free account
hub / github.com/boostorg/asio / transmit_file

Function transmit_file

example/cpp11/windows/transmit_file.cpp:32–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30// A wrapper for the TransmitFile overlapped I/O operation.
31template <typename Handler>
32void 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
61class connection
62 : public std::enable_shared_from_this<connection>

Callers 1

startMethod · 0.85

Calls 6

contextMethod · 0.45
get_executorMethod · 0.45
native_handleMethod · 0.45
getMethod · 0.45
completeMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected