reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
Timer.cxx
Go to the documentation of this file.
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#include "rutil/Socket.hxx"
6
7#if defined( WIN32 )
8# include <windows.h>
9# include <winbase.h>
10#else
11# include <sys/time.h>
12# include <sys/syscall.h>
13# include <unistd.h>
14#endif
15
16#include "rutil/ResipAssert.h"
17#include "rutil/Time.hxx"
18#include "rutil/Timer.hxx"
19#include "rutil/Logger.hxx"
20
21
22#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
23
24using namespace resip;
25
26unsigned long
28
29unsigned long
30resip::Timer::T2 = 8 * T1;
31
32unsigned long
33resip::Timer::T4 = 10 * T1;
34
35unsigned long
37
38unsigned long
39resip::Timer::TB = 64*T1;
40
41unsigned long
42resip::Timer::TD = 32000;
43
44unsigned long
45resip::Timer::TC = 3*60*1000;
46
47unsigned long
48resip::Timer::TF = 64*T1;
49
50unsigned long
51resip::Timer::TH = 64*T1;
52
53unsigned long
54resip::Timer::TS = 32000;
55
56unsigned long
58
59void
60Timer::resetT1(unsigned long t1)
61{
62 T1 = t1;
63 T2 = 8 * T1;
64 T4 = 10 * T1;
65 TB = 64*T1;
66 TF = 64*T1;
67 TH = 64*T1;
68}
69
70Data
72{
73 switch (timer)
74 {
75 case TimerA: // doubling
76 return "Timer A";
77 case TimerB:
78 return "Timer B";
79 case TimerC:
80 return "Timer C";
81 case TimerD:
82 return "Timer D";
83 case TimerE1:
84 return "Timer E1";
85 case TimerE2:
86 return "Timer E2";
87 case TimerF:
88 return "Timer F";
89 case TimerG:
90 return "Timer G";
91 case TimerH:
92 return "Timer H";
93 case TimerI:
94 return "Timer I";
95 case TimerJ:
96 return "Timer J";
97 case TimerK:
98 return "Timer K";
99 case TimerTrying:
100 return "Timer Trying";
101 case TimerStaleClient:
102 return "Timer StaleClient";
103 case TimerStaleServer:
104 return "Timer StaleServer";
105 case TimerStateless:
106 return "Timer Stateless";
107 case TimerCleanUp:
108 return "Timer Cleanup";
109 case TcpConnectTimer:
110 return "TcpConnectTimer";
111 default:
112 resip_assert(0);
113 }
114 return "Bad Bad Bad in timer";
115}
116
117
118TransactionTimer::TransactionTimer(unsigned long ms,
119 Timer::Type type,
120 const Data& transactionId) :
121 mWhen(ms + Timer::getTimeMs()),
122 mType(type),
123 mTransactionId(transactionId),
124 mDuration(ms)
125{}
126
127std::ostream&
128TransactionTimer::encode(std::ostream& str) const
129{
131 str << "TransactionTimer[ when=" << mWhen << " rel=";
132 if (mWhen < now)
133 {
134 str << "past";
135 }
136 else
137 {
138 str << (mWhen - now);
139 }
140 str << "]";
141 return str;
142}
143
144#ifndef RESIP_USE_STL_STREAMS
146TransactionTimer::encode(EncodeStream& str) const
147{
149 str << "TransactionTimer[ when=" << mWhen << " rel=";
150 if (mWhen < now)
151 {
152 str << "past";
153 }
154 else
155 {
156 str << (mWhen - now);
157 }
158 str << "]";
159 return str;
160}
161#endif
162
163TimerWithPayload::TimerWithPayload(unsigned long ms, Message* message) :
164 mWhen(ms + Timer::getTimeMs()),
165 mMessage(message)
166{
168}
169
170std::ostream&
171TimerWithPayload::encode(std::ostream& str) const
172{
174 str << "TimerWithPayload[ when=" << mWhen << " rel=";
175 if (mWhen < now)
176 {
177 str << "past";
178 }
179 else
180 {
181 str << (mWhen - now);
182 }
183 str << "]";
184 return str;
185}
186
187#ifndef RESIP_USE_STL_STREAMS
189TimerWithPayload::encode(EncodeStream& str) const
190{
192 str << "TimerWithPayload[ when=" << mWhen << " rel=";
193 if (mWhen < now)
194 {
195 str << "past";
196 }
197 else
198 {
199 str << (mWhen - now);
200 }
201 str << "]";
202 return str;
203}
204#endif
205
206
207/* ====================================================================
208 * The Vovida Software License, Version 1.0
209 *
210 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
211 *
212 * Redistribution and use in source and binary forms, with or without
213 * modification, are permitted provided that the following conditions
214 * are met:
215 *
216 * 1. Redistributions of source code must retain the above copyright
217 * notice, this list of conditions and the following disclaimer.
218 *
219 * 2. Redistributions in binary form must reproduce the above copyright
220 * notice, this list of conditions and the following disclaimer in
221 * the documentation and/or other materials provided with the
222 * distribution.
223 *
224 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
225 * and "Vovida Open Communication Application Library (VOCAL)" must
226 * not be used to endorse or promote products derived from this
227 * software without prior written permission. For written
228 * permission, please contact vocal@vovida.org.
229 *
230 * 4. Products derived from this software may not be called "VOCAL", nor
231 * may "VOCAL" appear in their name, without prior written
232 * permission of Vovida Networks, Inc.
233 *
234 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
235 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
236 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
237 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
238 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
239 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
240 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
241 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
242 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
243 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
244 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
245 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
246 * DAMAGE.
247 *
248 * ====================================================================
249 *
250 * This software consists of voluntary contributions made by Vovida
251 * Networks, Inc. and many individuals on behalf of Vovida Networks,
252 * Inc. For more information on Vovida Networks, Inc., please see
253 * <http://www.vovida.org/>.
254 *
255 */
#define resip_assert(x)
This file needs to work for both C and C++ code.
Handles cross-platform sockets compatibility.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
The base-class used for message-passing.
Definition Message.hxx:21
EncodeStream & encode(EncodeStream &str) const
Definition Timer.cxx:189
This class is used to get the current system time.
Definition Timer.hxx:31
static unsigned long T100
Definition Timer.hxx:117
static unsigned long TF
Definition Timer.hxx:121
static Data toData(Type timer)
Definition Timer.cxx:71
static unsigned long TcpConnectTimeout
Definition Timer.hxx:127
static unsigned long TS
Definition Timer.hxx:125
static unsigned long TC
Definition Timer.hxx:120
static unsigned long T1
Definition Timer.hxx:114
@ TimerStateless
Definition Timer.hxx:51
@ TimerStaleClient
Definition Timer.hxx:49
@ TcpConnectTimer
Definition Timer.hxx:54
@ TimerStaleServer
Definition Timer.hxx:50
static void resetT1(unsigned long t1)
Definition Timer.cxx:60
static unsigned long TB
Definition Timer.hxx:119
static unsigned long TH
Definition Timer.hxx:122
static uint64_t getTimeMs()
Returns the current clock time in milliseconds.
Definition Timer.hxx:72
static unsigned long T4
Definition Timer.hxx:116
static unsigned long T2
Definition Timer.hxx:115
static unsigned long TD
Definition Timer.hxx:124
EncodeStream & encode(EncodeStream &str) const
Definition Timer.cxx:146
dcm! – add UnusedChecking(_enum) below;
unsigned long long uint64_t
Definition Stun.hxx:39
#define EncodeStream