]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_asio_frontend_timer.h
b7d6a63b46f114fb5debdd042138ef5be1b646fe
3 #include <boost/asio/basic_waitable_timer.hpp>
4 #include <boost/intrusive_ptr.hpp>
6 #include "common/ceph_time.h"
10 // a WaitHandler that closes a stream if the timeout expires
11 template <typename Stream
>
12 struct timeout_handler
{
13 // this handler may outlive the timer/stream, so we need to hold a reference
14 // to keep the stream alive
15 boost::intrusive_ptr
<Stream
> stream
;
17 explicit timeout_handler(boost::intrusive_ptr
<Stream
> stream
) noexcept
18 : stream(std::move(stream
)) {}
20 void operator()(boost::system::error_code ec
) {
21 if (!ec
) { // wait was not canceled
22 boost::system::error_code ec_ignored
;
23 stream
->close(ec_ignored
);
28 // a timeout timer for stream operations
29 template <typename Clock
, typename Executor
, typename Stream
>
30 class basic_timeout_timer
{
32 using clock_type
= Clock
;
33 using duration
= typename
clock_type::duration
;
34 using executor_type
= Executor
;
36 explicit basic_timeout_timer(const executor_type
& ex
, duration dur
,
37 boost::intrusive_ptr
<Stream
> stream
)
38 : timer(ex
), dur(dur
), stream(std::move(stream
))
41 basic_timeout_timer(const basic_timeout_timer
&) = delete;
42 basic_timeout_timer
& operator=(const basic_timeout_timer
&) = delete;
45 if (dur
.count() > 0) {
46 timer
.expires_after(dur
);
47 timer
.async_wait(timeout_handler
{stream
});
52 if (dur
.count() > 0) {
58 using Timer
= boost::asio::basic_waitable_timer
<clock_type
,
59 boost::asio::wait_traits
<clock_type
>, executor_type
>;
62 boost::intrusive_ptr
<Stream
> stream
;