reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
FlowDtlsTimerContext.cxx
Go to the documentation of this file.
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#ifdef USE_SSL
6
7#include <functional>
8
9#include <rutil/Log.hxx>
10#include <rutil/Logger.hxx>
11
14
15using namespace flowmanager;
16using namespace resip;
17using namespace dtls;
18using namespace std;
19
20#define RESIPROCATE_SUBSYSTEM FlowManagerSubsystem::FLOWMANAGER
21
22using namespace std::chrono;
23
24FlowDtlsTimerContext::FlowDtlsTimerContext(asio::io_context& ioService) :
25 mIOService(ioService),
26 mStopped(false)
27{
28}
29
30void
31FlowDtlsTimerContext::addTimer(std::shared_ptr<dtls::DtlsTimer> timer, unsigned int durationMs)
32{
33 std::lock_guard<std::mutex> lock(mMutex);
34 if(mStopped)
35 {
36 return; // timer is freed when its owner lets it go
37 }
38
39 // The handler holds timer until it runs: when the asio timer expires, or is cancelled by stop()
40 auto deadlineTimer = std::make_shared<asio::steady_timer>(mIOService);
41 deadlineTimer->expires_after(milliseconds(durationMs));
42 deadlineTimer->async_wait([this, timer, deadlineTimer](const asio::error_code& errorCode)
43 {
44 {
45 std::lock_guard<std::mutex> lock(mMutex);
46 mPending.erase(deadlineTimer);
47 }
48 if(!errorCode)
49 {
50 timer->fire();
51 }
52 else if(errorCode != asio::error::operation_aborted)
53 {
54 ErrLog(<< "Timer error: " << errorCode.message());
55 }
56 });
57 mPending.insert(deadlineTimer);
58}
59
60void
62{
63 {
64 std::lock_guard<std::mutex> lock(mMutex);
65 mStopped = true;
66 }
67 // An asio timer can't be used from two threads at once: cancel them on the io thread
68 asio::post(mIOService, [this]()
69 {
70 std::lock_guard<std::mutex> lock(mMutex);
71 for(const auto& deadlineTimer : mPending)
72 {
73 deadlineTimer->cancel();
74 }
75 });
76}
77
78#endif
79
80/* ====================================================================
81
82 Copyright (c) 2008-2026, SIP Spectrum, Inc. http://sipspectrum.com
83 Copyright (c) 2007-2008, Plantronics, Inc.
84 All rights reserved.
85
86 Redistribution and use in source and binary forms, with or without
87 modification, are permitted provided that the following conditions are
88 met:
89
90 1. Redistributions of source code must retain the above copyright
91 notice, this list of conditions and the following disclaimer.
92
93 2. Redistributions in binary form must reproduce the above copyright
94 notice, this list of conditions and the following disclaimer in the
95 documentation and/or other materials provided with the distribution.
96
97 3. Neither the name of Plantronics nor the names of its contributors
98 may be used to endorse or promote products derived from this
99 software without specific prior written permission.
100
101 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
102 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
103 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
104 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
105 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
106 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
107 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
108 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
109 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
110 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
111 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
112
113 ==================================================================== */
#define ErrLog(args_)
Definition Logger.hxx:137
FlowDtlsTimerContext(asio::io_context &ioService)
void addTimer(std::shared_ptr< dtls::DtlsTimer > timer, unsigned int durationMs) override
This class is used during media sessions that use Dtls-Srtp for a media transport.
Definition ErrorCode.hxx:4
dcm! – add UnusedChecking(_enum) below;