Skip to content

Commit

Permalink
Just a backup commit.
Browse files Browse the repository at this point in the history
Some methods become noexcept.

--HG--
branch : 0.6-dev--exception-safety
  • Loading branch information
eao197 committed Aug 20, 2019
1 parent 4a7b167 commit 4f483d7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 25 deletions.
14 changes: 11 additions & 3 deletions dev/restinio/asio_timer_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

#include <restinio/asio_include.hpp>

#include <restinio/utils/suppress_exceptions.hpp>

#include <restinio/timer_common.hpp>
#include <restinio/compiler_features.hpp>

namespace restinio
{
Expand All @@ -40,7 +43,7 @@ class asio_timer_manager_t final
public:
timer_guard_t(
asio_ns::io_context & io_context,
std::chrono::steady_clock::duration check_period )
std::chrono::steady_clock::duration check_period ) noexcept
: m_operation_timer{ io_context }
, m_check_period{ check_period }
{}
Expand All @@ -63,10 +66,15 @@ class asio_timer_manager_t final
}

//! Cancel timeout guard if any.
/*!
* @note
* Since v.0.6.0 this method is noexcept.
*/
void
cancel()
cancel() noexcept
{
m_operation_timer.cancel();
restinio::utils::suppress_exceptions_quietly(
[this]{ m_operation_timer.cancel(); } );
}

private:
Expand Down
6 changes: 6 additions & 0 deletions dev/restinio/compiler_features.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@
#define RESTINIO_NODISCARD
#endif

//FIXME: document this!
#define RESTINIO_ENSURE_NOEXCEPT_CALL(expr) \
static_assert(noexcept(expr), "this call is expected to be noexcept: " #expr); \
expr


31 changes: 18 additions & 13 deletions dev/restinio/impl/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ class connection_t final

//! Standard close routine.
void
close()
close() noexcept
{
restinio::utils::log_trace_noexcept( m_logger,
[&]{
Expand All @@ -1262,11 +1262,17 @@ class connection_t final
connection_id() );
} );

asio_ns::error_code ignored_ec;
m_socket.shutdown(
asio_ns::ip::tcp::socket::shutdown_both,
ignored_ec );
m_socket.close();
// shutdown() and close() should be called regardless of
// possible exceptions.
restinio::utils::suppress_exceptions_quietly( [this] {
asio_ns::error_code ignored_ec;
m_socket.shutdown(
asio_ns::ip::tcp::socket::shutdown_both,
ignored_ec );
} );
restinio::utils::suppress_exceptions_quietly( [this] {
m_socket.close();
} );

restinio::utils::log_trace_noexcept( m_logger,
[&]{
Expand All @@ -1276,8 +1282,7 @@ class connection_t final
} );

// Clear stuff.

cancel_timeout_checking();
RESTINIO_ENSURE_NOEXCEPT_CALL( cancel_timeout_checking() );

restinio::utils::log_trace_noexcept( m_logger,
[&]{
Expand All @@ -1286,6 +1291,7 @@ class connection_t final
connection_id() );
} );

//FIXME: this call should be noexcept!
m_response_coordinator.reset();

restinio::utils::log_trace_noexcept( m_logger,
Expand Down Expand Up @@ -1313,15 +1319,14 @@ class connection_t final
*/
template< typename Message_Builder >
void
trigger_error_and_close( Message_Builder msg_builder )
//FIXME: should this method be noexcept?
trigger_error_and_close( Message_Builder msg_builder ) noexcept
{
// An exception from logger/msg_builder shouldn't prevent
// a call to close().
restinio::utils::log_error_noexcept(
m_logger, std::move(msg_builder) );

close();
RESTINIO_ENSURE_NOEXCEPT_CALL( close() );
}
//! \}

Expand Down Expand Up @@ -1406,10 +1411,10 @@ class connection_t final

//! Stop timout guarding.
void
cancel_timeout_checking()
cancel_timeout_checking() noexcept
{
m_current_timeout_cb = nullptr;
m_timer_guard.cancel();
RESTINIO_ENSURE_NOEXCEPT_CALL( m_timer_guard.cancel() );
}

//! Helper function to work with timer guard.
Expand Down
7 changes: 3 additions & 4 deletions dev/restinio/impl/connection_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,9 @@ struct connection_settings_t final
return m_timer_manager->create_timer_guard();
}

private:

//! Timer factory for timout guards.
timer_manager_handle_t m_timer_manager;
private:
//! Timer factory for timout guards.
timer_manager_handle_t m_timer_manager;
};

template < typename Traits >
Expand Down
15 changes: 10 additions & 5 deletions dev/restinio/so5/so_timer_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include <restinio/asio_include.hpp>
#include <restinio/compiler_features.hpp>

#include <so_5/all.hpp>

Expand Down Expand Up @@ -80,11 +81,15 @@ class so_timer_manager_t final
}
}

// Cancel timeout guard if any.
//! Cancel timeout guard if any.
/*!
* @note
* Since v.0.6.0 this method is noexcept.
*/
void
cancel()
cancel() noexcept
{
m_current_op_timer.release();
RESTINIO_ENSURE_NOEXCEPT_CALL( m_current_op_timer.release() );
}

private:
Expand All @@ -105,8 +110,8 @@ class so_timer_manager_t final

//! Start/stop timer manager.
//! \{
void start() const {}
void stop() const {}
void start() const noexcept {}
void stop() const noexcept {}
//! \}

struct factory_t
Expand Down

0 comments on commit 4f483d7

Please sign in to comment.