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 )
151 asio_ns::error_code ec;
153 if( !m_socket.native_non_blocking() )
155 m_socket.native_non_blocking(
true, ec );
160 m_after_sendfile_cb( ec, m_transfered_size );
169 auto wait_write_is_possible =
173 asio_ns::ip::tcp::socket::wait_write,
174 asio_ns::bind_executor(
176 [
this, ctx =
this->shared_from_this() ]
177 (
const asio_ns::error_code & ec ){
178 if( ec || 0 == m_remained_size )
180 m_after_sendfile_cb( ec, m_transfered_size );
189 if( 0 == m_remained_size )
192 wait_write_is_possible();
196 #if defined( RESTINIO_FREEBSD_TARGET ) 206 m_socket.native_handle(),
208 static_cast< size_t >(
209 std::min< file_size_t >( m_remained_size, m_chunk_size ) ),
213 #if __FreeBSD__ >= 11
214 SF_FLAGS( 16, SF_NOCACHE )
221 m_next_write_offset += n;
226 m_remained_size -=
static_cast< file_size_t >( n );
227 m_transfered_size +=
static_cast< file_size_t >( n );
231 #elif defined( RESTINIO_MACOS_TARGET ) 237 static_cast< off_t >(
238 std::min< file_size_t >( m_remained_size, m_chunk_size ) );
243 m_socket.native_handle(),
250 m_next_write_offset += n;
255 m_remained_size -=
static_cast< file_size_t >( n );
256 m_transfered_size +=
static_cast< file_size_t >( n );
263 m_socket.native_handle(),
265 &m_next_write_offset,
266 std::min< file_size_t >( m_remained_size, m_chunk_size ) );
271 if( errno == EAGAIN || errno == EINTR )
273 wait_write_is_possible();
277 const asio_ns::error_code ec{ errno, asio_ns::error::get_system_category() };
278 m_after_sendfile_cb( ec, m_transfered_size );
285 wait_write_is_possible();
290 m_remained_size -=
static_cast< file_size_t >( n );
291 m_transfered_size +=
static_cast< file_size_t >( n );
sendfile_operation_runner_t(const sendfile_operation_runner_t &)=delete
virtual void start() override
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
sendfile_operation_runner_t & operator=(sendfile_operation_runner_t &&)=delete
sendfile_operation_runner_t & operator=(sendfile_operation_runner_t &&)=delete
virtual void start() override
A specialization for plain tcp-socket using linux sendfile() (http://man7.org/linux/man-pages/man2/se...
std::unique_ptr< char[] > m_buffer
sendfile_operation_runner_t & operator=(const sendfile_operation_runner_t &)=delete
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, optional_t< Value_Type > >::type opt_value(const Parameter_Container ¶ms, string_view_t key)
Gets the value of a parameter specified by key wrapped in optional_t<Value_Type> if parameter exists ...
sendfile_operation_runner_t & operator=(const sendfile_operation_runner_t &)=delete