Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old FIXME resolution #194

Merged
merged 17 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions dev/restinio/async_chain/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ using generic_async_request_scheduler_t =

/*!
* @brief Special type to be used as an indicator that there are no more
* handlers in an async chain.
* schedulers in an async chain.
*
* This type will be used in on_next_result_t variant.
*
Expand All @@ -109,7 +109,7 @@ struct no_more_schedulers_t {};
* @brief Special type to be used as result of async_handling_controller's
* on_next method.
*
* The async_handling_controller_t::on_next may return an actual handler to
* The async_handling_controller_t::on_next may return an actual scheduler to
* be called or (if there are no more handlers left) a special no_more_handler
* value. This is described by on_next_result_t variant type.
*
Expand Down Expand Up @@ -165,7 +165,7 @@ class async_handling_controller_t
virtual ~async_handling_controller_t() = default;

/*!
* @brief Get reference to source request.
* @brief Get reference to the source request.
*
* Usage example:
* @code
Expand All @@ -188,11 +188,11 @@ class async_handling_controller_t

private:
/*!
* @brief Command to try find a next async handler to be invoked.
* @brief Command to try find a next scheduler to be invoked.
*
* Implementation of async_handling_controller_t should switch to the
* next handler in the chain and return the handler to be called next.
* If there are no such handlers, no_more_schedulers_t must be returned.
* next scheduler in the chain and return the scheduler to be called next.
* If there are no such schedulers, no_more_schedulers_t must be returned.
*
* @note
* This method is intended to be called by next() function.
Expand All @@ -208,7 +208,7 @@ namespace impl
/*!
* @brief Helper to make a negative response with "Not Implemented" status.
*
* This helper will be used if there is no more handlers to call, but
* This helper will be used if there is no more schedulers to call, but
* the request is still not handled.
*
* @tparam Request_Handle Type of request handle that holds the source request.
Expand All @@ -225,7 +225,7 @@ make_not_implemented_response( const Request_Handle & req )
/*!
* @brief Helper to make a negative response with "Internal Server Error" status.
*
* This helper will be used if the current async handler returns
* This helper will be used if the current scheduler returns
* schedule_result_t::failure.
*
* @tparam Request_Handle Type of request handle that holds the source request.
Expand Down
20 changes: 11 additions & 9 deletions dev/restinio/async_chain/fixed_size.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ namespace restinio::async_chain
* @brief A holder of fixed-size chain of asynchronous handlers.
*
* @note
* An instance of that type is intended to be filled with actual handlers
* at the creation time. After that new handlers can't be added to the chain,
* An instance of that type is intended to be filled with actual schedulers
* at the creation time. After that new schedulers can't be added to the chain,
* and old handlers can't be removed from the chain.
*
* Usage example for the case when there is no extra-data in a request object
* (please note that this is simplified example without actual asynchronous code):
* (please note that this is simplified example without actual asynchronous code,
* all schedulers work as synchronous handlers):
* @code
* struct my_traits : public restinio::default_traits_t {
* using request_handler_t = restinio::async_chain::fixed_size_chain_t<3>;
Expand Down Expand Up @@ -90,7 +91,8 @@ namespace restinio::async_chain
*
* Usage example for the case when some extra-data is incorporated into
* a request object
* (please note that this is simplified example without actual asynchronous code):
* (please note that this is simplified example without actual asynchronous code,
* all schedulers work as synchronous handlers):
* @code
* struct my_extra_data_factory {
* // A data formed by checker of HTTP-fields.
Expand Down Expand Up @@ -164,7 +166,7 @@ namespace restinio::async_chain
* );
* @endcode
*
* @tparam Size The exact number of handlers in the chain.
* @tparam Size The exact number of schedulers in the chain.
*
* @tparam Extra_Data_Factory The type of extra-data-factory specified in
* the server's traits.
Expand Down Expand Up @@ -197,7 +199,7 @@ class fixed_size_chain_t
* @brief Actual implementation of the controller interface.
*
* @note
* Object of this type holds a copy of the source array of handlers.
* Object of this type holds a copy of the source array of schedulers.
*/
class actual_controller_t final
: public async_handling_controller_t< Extra_Data_Factory >
Expand All @@ -206,7 +208,7 @@ class fixed_size_chain_t
const actual_request_handle_t m_request;
//! Request handlers.
schedulers_array_t m_schedulers;
//! Index of the current handler to be used.
//! Index of the current scheduler to be used.
/*!
* @note
* May be equal to or greater than m_schedulers.size() in the case
Expand Down Expand Up @@ -246,7 +248,7 @@ class fixed_size_chain_t
}
};

//! The array of request handlers.
//! The array of schedulers.
/*!
* @note
* It's initialized in the constructor and then never changed.
Expand Down Expand Up @@ -298,7 +300,7 @@ class fixed_size_chain_t
}

/*!
* Initiates execution of the first request handler in the chain.
* Initiates execution of the first scheduler in the chain.
*
* @note
* Always returns request_handling_status_t::accepted.
Expand Down
26 changes: 14 additions & 12 deletions dev/restinio/async_chain/growable_size.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ namespace restinio::async_chain
* @brief A holder of variable-size chain of asynchronous handlers.
*
* @note
* Once a list of handler is filled and an instance of growable_size_chain_t
* is created that instance can't be changed: a new handler can't be added, and
* an old handler can be removed. The creation of growable_size_chain_t
* Once a list of schedulers is filled and an instance of growable_size_chain_t
* is created that instance can't be changed: a new scheduler can't be added, and
* an old scheduler can be removed. The creation of growable_size_chain_t
* instance is performed by the help of growable_size_chain_t::builder_t
* class.
*
* Usage example for the case when there is no extra-data in a request object
* (please note that this is simplified example without actual asynchronous code):
* (please note that this is simplified example without actual asynchronous code,
* all schedulers work as synchronous handlers):
* @code
* struct my_traits : public restinio::default_traits_t {
* using request_handler_t = restinio::async_chain::growable_size_chain_t;
Expand Down Expand Up @@ -90,7 +91,8 @@ namespace restinio::async_chain
*
* Usage example for the case when some extra-data is incorporated into
* a request object:
* (please note that this is simplified example without actual asynchronous code):
* (please note that this is simplified example without actual asynchronous code,
* all schedulers work as synchronous handlers):
* @code
* struct my_extra_data_factory {
* // A data formed by checker of HTTP-fields.
Expand Down Expand Up @@ -202,20 +204,20 @@ class growable_size_chain_t
* @brief Actual implementation of the controller interface.
*
* @note
* Object of this type holds a copy of the source vector of handlers.
* Object of this type holds a copy of the source vector of schedulers.
*/
class actual_controller_t final
: public async_handling_controller_t< Extra_Data_Factory >
{
//! The source request.
const actual_request_handle_t m_request;
//! Request handlers.
//! Request schedulers.
schedulers_vector_t m_schedulers;
//! Index of the current scheduler to be used.
/*!
* @note
* May be equal to or greater than m_schedulers.size() in the case
* when all handlers are already processed.
* when all schedulers are already processed.
*/
std::size_t m_current{};

Expand Down Expand Up @@ -261,7 +263,7 @@ class growable_size_chain_t
* That instance can be obtained by release() method.
*
* @note
* New handlers can be added to the chain by add() method until
* New schedulers can be added to the chain by add() method until
* release() is called.
*
* @attention
Expand All @@ -278,7 +280,7 @@ class growable_size_chain_t
{}

/*!
* @brief Stop adding of new handlers and acquire the chain instance.
* @brief Stop adding of new schedulers and acquire the chain instance.
*
* @note
* The builder object should not be used after the calling of
Expand Down Expand Up @@ -314,7 +316,7 @@ class growable_size_chain_t
};

private:
//! The vector of request handlers.
//! The vector of schedulers.
schedulers_vector_t m_schedulers;

/*!
Expand All @@ -334,7 +336,7 @@ class growable_size_chain_t
growable_size_chain_t() = delete;

/*!
* Initiates execution of the first request handler in the chain.
* Initiates execution of the first scheduler in the chain.
*
* @note
* Always returns request_handling_status_t::accepted.
Expand Down
2 changes: 0 additions & 2 deletions dev/restinio/expected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ namespace restinio
template< typename T, typename E >
using expected_t = nonstd::expected<T, E>;

//FIXME: is this symbol actually present in expected-lite?
// using nonstd::make_expected;
using nonstd::make_unexpected;

} /* namespace restinio */
Expand Down
20 changes: 0 additions & 20 deletions dev/restinio/helpers/easy_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4261,26 +4261,6 @@ non_negative_decimal_number_p( digits_to_consume_t digits_limit ) noexcept
};
}

//FIXME: remove in v.0.7.0!
//
// positive_decimal_number_p
//
/*!
* @brief A factory function to create a producer for non-negative
* decimal numbers.
*
* @deprecated Use non_negative_decimal_number_p.
*
* @since v.0.6.2
*/
template< typename T >
[[deprecated]] [[nodiscard]]
inline auto
positive_decimal_number_producer() noexcept
{
return non_negative_decimal_number_p<T>();
}

//
// hexadecimal_number_p
//
Expand Down
59 changes: 44 additions & 15 deletions dev/restinio/http_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ external_io_context( asio_ns::io_context & ctx )
\endcode

Async way for starting and stopping a http_server can be used if
http_server_t::open_async() and http_server_t::open_async() can be
http_server_t::open_async() and http_server_t::close_async() can be
called from any other thread. For example:
\code
asio::io_context io_ctx;
Expand All @@ -150,14 +150,18 @@ external_io_context( asio_ns::io_context & ctx )
io_ctx.run();
} };

// This variable will be used for holding information about
// a possible exception in open_async.
std::exception_ptr exception_from_open_async;

// Start server in async way. Actual start will be performed
// on the context of server_thread.
server.open_async(
// Ok callback. Nothing to do.
[]{},
// Error callback. Rethrow an exception.
[]( auto ex_ptr ) {
std::rethrow_exception( ex_ptr );
[]() noexcept {},
// Error callback. Just store information about an exception.
[&]( std::exception_ptr ex_ptr ) noexcept {
exception_from_open_async = ex_ptr;
} );
...
// Wait while server_thread finishes its work.
Expand Down Expand Up @@ -228,7 +232,7 @@ class http_server_t
// allows to call operator() with server_settings_t& arg.
typename = decltype(
std::declval<Configurator>()(
*(static_cast<server_settings_t<Traits>*>(nullptr)))) >
std::declval<server_settings_t<Traits>&>() ) ) >
http_server_t(
io_context_holder_t io_context,
Configurator && configurator )
Expand Down Expand Up @@ -303,15 +307,40 @@ class http_server_t

//! Closes server in async way.
/*!
\note It doesn't call io_context to stop
(\see stop_io_context()).

\attention
\a close_ok_cb and \a close_err_cb should be noexcept
functions/lambdas. This requirement is not enforced by
static_assert in RESTinio's code to avoid problems in
cases when `std::function` is used for these callbacks.
*/
* Usage example:
* \code
* restinio::http_server_t< my_traits > server{ ... };
*
* server.open_async(...);
*
* // It's time to close the server.
* server.close_async(
* // OK callback. Will be called if acceptor and other
* // stuff is closed without problems.
* // Please note that OK callback should not throw exceptions.
* [&]() noexcept {
* ... // Some actions to perform if everything is OK.
* // For example, shutting down worker threads.
* },
* // Error callback. Will be called if an exception is thrown
* // during closing acceptor or other stuff.
* // Please note that error callback should not throw exceptions.
* []( std::exception_ptr ex ) noexcept {
* ... // Some actions. Like storing `ex` somewhere.
* } );
* \endcode
*
* \attention
* If an error is thrown during closing the acceptor and other stuff,
* the \a close_err_cb is called, but the state of the http_server_t
* is undefined.
*
* \attention
* \a close_ok_cb and \a close_err_cb should be noexcept
* functions/lambdas. This requirement is not enforced by
* static_assert in RESTinio's code to avoid problems in
* cases when `std::function` is used for these callbacks.
*/
template <
typename Server_Close_Ok_CB,
typename Server_Close_Error_CB >
Expand Down
Loading