RESTinio
sendfile_operation.hpp
Go to the documentation of this file.
1 /*
2  restinio
3 */
4 
5 /*!
6  sendfile routine.
7 */
8 
9 #pragma once
10 
11 #include <memory>
12 
13 #include <restinio/sendfile.hpp>
14 
15 namespace restinio
16 {
17 
18 namespace impl
19 {
20 
21 //
22 // sendfile_operation_base_t
23 //
24 
25 //!Base class for storing sendfile operation context.
28 {
29  public:
30  virtual ~sendfile_operation_base_t() = default;
31 
32  virtual void
33  start() = 0;
34 };
35 
37 
38 //! Callback type for invokation when sendfile operation completes.
39 using after_sendfile_cb_t =
40  std::function< void ( const asio_ns::error_code & , file_size_t ) >;
41 
42 //
43 // sendfile_operation_runner_base_t
44 //
45 
46 //! A base runner of sendfile operation (keeps all the data).
47 template < typename Socket >
50 {
51  public:
53 
55  const sendfile_t & sf,
56  asio_ns::executor executor,
57  Socket & socket,
58  after_sendfile_cb_t after_sendfile_cb )
61  , m_remained_size{ sf.size() }
64  , m_executor{ std::move( executor )}
65  , m_socket{ socket }
67  {}
68 
69  auto expires_after() const noexcept { return m_expires_after; }
70 
71  protected:
76 
78 
80 
82  Socket & m_socket;
84 };
85 
86 template<typename Error_Type>
87 auto
88 make_error_code( const Error_Type & e )
89 {
90  return asio_ns::error_code{ static_cast<int>(e), asio_ns::error::get_system_category() };
91 }
92 
93 } /* namespace impl */
94 
95 } /* namespace restinio */
96 
97 /*
98  Concrete implementations.
99 */
100 
101 #if defined( _MSC_VER ) || defined( __MINGW32__ )
102  #include "sendfile_operation_win.ipp"
103 #elif (defined( __clang__ ) || defined( __GNUC__ )) && !defined(__WIN32__)
104  #include "sendfile_operation_posix.ipp"
105 #else
106  #if defined (RESTINIO_ENABLE_SENDFILE_DEFAULT_IMPL)
107  #include "sendfile_operation_default.ipp"
108  #else
109  #error "Sendfile not supported, to enable default implementation define RESTINIO_ENABLE_SENDFILE_DEFAULT_IMPL macro"
110  #endif
111 #endif
const std::chrono::steady_clock::time_point m_expires_after
Base class for storing sendfile operation context.
A base runner of sendfile operation (keeps all the data).
auto make_error_code(const Error_Type &e)
sendfile_operation_runner_base_t(const sendfile_t &sf, asio_ns::executor executor, Socket &socket, after_sendfile_cb_t after_sendfile_cb)
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 &params, string_view_t key)
Gets the value of a parameter specified by key wrapped in optional_t<Value_Type> if parameter exists ...
Definition: value_or.hpp:64