reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
DtlsTimer.hxx
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#ifndef DTLS_Timer_hxx
8#define DTLS_Timer_hxx
9
10#include <memory>
11#include <mutex>
12
13namespace dtls
14{
15
16// A timer is shared by its owner, which can invalidate it, and the DtlsTimerContext it's added
17// to, which fires it when it expires: it's freed when both have let it go, whether it fired,
18// was invalidated, or was dropped unfired (eg. cancelled at shutdown).
20{
21 public:
22 DtlsTimer(unsigned int seq);
23 virtual ~DtlsTimer();
24
25 virtual void expired()=0;
26 // Calls expired(), unless the timer has been invalidated
27 virtual void fire();
28 unsigned int getSeq() { return mSeq; }
29 // The owner no longer wants the timer to fire
30 void invalidate() { mValid = false; }
31
32 // The lock the timer's owner holds while it uses what the timer acts on, and while it
33 // invalidates the timer: fire() takes it too, so a timer firing on another thread neither
34 // races the owner nor runs for an owner that has invalidated it meanwhile. Shared, so it
35 // outlives the owner while the timer is pending.
36 void setLock(std::shared_ptr<std::mutex> lock) { mLock = std::move(lock); }
37 private:
38 unsigned int mSeq;
39 bool mValid;
40 std::shared_ptr<std::mutex> mLock;
41};
42
43
45{
46 public:
47 virtual ~DtlsTimerContext() {}
48 // Fires timer after waitMs, keeping its reference until then (or until it drops the timer
49 // unfired)
50 virtual void addTimer(std::shared_ptr<DtlsTimer> timer, unsigned int waitMs)=0;
51 protected:
52 // The caller must hold a reference to timer: firing it can release the owner's
53 void fire(DtlsTimer *timer);
54};
55
56
57}
58
59#endif
60
61#endif
62/* ====================================================================
63
64 Copyright (c) 2007-2026, SIP Spectrum, Inc. http://sipspectrum.com
65 Copyright (c) 2007-2008, Eric Rescorla and Derek MacDonald
66 All rights reserved.
67
68 Redistribution and use in source and binary forms, with or without
69 modification, are permitted provided that the following conditions are
70 met:
71
72 1. Redistributions of source code must retain the above copyright
73 notice, this list of conditions and the following disclaimer.
74
75 2. Redistributions in binary form must reproduce the above copyright
76 notice, this list of conditions and the following disclaimer in the
77 documentation and/or other materials provided with the distribution.
78
79 3. None of the contributors names may be used to endorse or promote
80 products derived from this software without specific prior written
81 permission.
82
83 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
84 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
85 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
86 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
87 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
88 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
89 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
90 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
91 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
92 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
93 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
94
95 ==================================================================== */
virtual ~DtlsTimerContext()
Definition DtlsTimer.hxx:47
virtual void addTimer(std::shared_ptr< DtlsTimer > timer, unsigned int waitMs)=0
void fire(DtlsTimer *timer)
Definition DtlsTimer.cxx:37
void setLock(std::shared_ptr< std::mutex > lock)
Definition DtlsTimer.hxx:36
unsigned int getSeq()
Definition DtlsTimer.hxx:28
virtual void expired()=0
virtual void fire()
Definition DtlsTimer.cxx:22
virtual ~DtlsTimer()
Definition DtlsTimer.cxx:17
void list()
Definition userAdmin.cxx:66