9 #if defined( RESTINIO_FREEBSD_TARGET ) || defined( RESTINIO_MACOS_TARGET ) 12 #include <sys/sendfile.h> 26 template <
typename Socket >
44 #if defined( RESTINIO_FREEBSD_TARGET ) || defined( RESTINIO_MACOS_TARGET ) 50 if(
static_cast<
off_t >( -1 ) !=
n )
77 auto const n = ::
read(
136 return [
this, ctx =
this->shared_from_this()]
138 (
const asio_ns::error_code & ec, std::size_t written )
noexcept 142 this->m_remained_size -= written;
143 this->m_transfered_size += written;
144 if( 0 ==
this->m_remained_size )
146 this->m_after_sendfile_cb(
148 this->m_transfered_size );
152 this->init_next_write();
157 this->m_after_sendfile_cb(
159 this->m_transfered_size );
179 if( !m_socket.native_non_blocking() )
181 asio_ns::error_code ec;
182 m_socket.native_non_blocking(
true, ec );
186 m_after_sendfile_cb( ec, m_transfered_size );
194 #if defined( RESTINIO_FREEBSD_TARGET ) 215 #if __FreeBSD__ >= 11
236 #elif defined( RESTINIO_MACOS_TARGET ) 246 static_cast<
off_t >(
278 m_socket.native_handle(),
280 &m_next_write_offset,
281 std::min< file_size_t >( m_remained_size, m_chunk_size ) );
295 asio_ns::ip::tcp::socket::wait_write,
296 asio_ns::bind_executor(
298 [
this, ctx =
this->shared_from_this() ]
300 (
const asio_ns::error_code & ec )
noexcept {
301 if( ec || 0 == m_remained_size )
303 m_after_sendfile_cb( ec, m_transfered_size );
314 make_asio_compaible_error(
315 asio_convertible_error_t::async_write_call_failed ),
355 if( 0 == m_remained_size )
364 const auto n = call_native_sendfile();
368 if( errno == EAGAIN || errno == EINTR )
377 errno, asio_ns::error::get_system_category() },
392 m_remained_size -=
static_cast< file_size_t >( n );
393 m_transfered_size +=
static_cast< file_size_t >( n );
void init_next_write() noexcept
sendfile_operation_runner_t(const sendfile_operation_runner_t &)=delete
virtual void start() override
void init_next_write() noexcept
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, std::optional< Value_Type > >::type opt_value(const Parameter_Container ¶ms, string_view_t key)
Gets the value of a parameter specified by key wrapped in std::optional<Value_Type> if parameter exis...
sendfile_operation_runner_t(sendfile_operation_runner_t &&)=delete
A runner of sendfile operation.
sendfile_operation_runner_t(sendfile_operation_runner_t &&)=delete
sendfile_operation_runner_t(const sendfile_operation_runner_t &)=delete
auto make_async_write_handler() noexcept
Helper method for making a lambda for async_write completion handler.
sendfile_operation_runner_t & operator=(sendfile_operation_runner_t &&)=delete
sendfile_operation_runner_t & operator=(sendfile_operation_runner_t &&)=delete
bool try_initiate_waiting_for_write_readiness() noexcept
virtual void start() override
A specialization for plain tcp-socket using linux sendfile() (http://man7.org/linux/man-pages/man2/se...
auto call_native_sendfile() noexcept
std::unique_ptr< char[] > m_buffer
bool try_turn_non_blocking_mode() noexcept
sendfile_operation_runner_t & operator=(const sendfile_operation_runner_t &)=delete
sendfile_operation_runner_t & operator=(const sendfile_operation_runner_t &)=delete