|
reSIProcate/rutil
9694
|
00001 #ifdef HAVE_CONFIG_H 00002 #include "config.h" 00003 #endif 00004 00005 #include "rutil/Socket.hxx" 00006 00007 #if defined( WIN32 ) 00008 # include <windows.h> 00009 # include <winbase.h> 00010 #else 00011 # include <sys/time.h> 00012 # include <sys/syscall.h> 00013 # include <unistd.h> 00014 #endif 00015 00016 #include <cassert> 00017 #include "rutil/Time.hxx" 00018 #include "rutil/Timer.hxx" 00019 #include "rutil/Logger.hxx" 00020 00021 00022 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP 00023 00024 using namespace resip; 00025 00026 unsigned long 00027 resip::Timer::T1 = 500; 00028 00029 unsigned long 00030 resip::Timer::T2 = 8 * T1; 00031 00032 unsigned long 00033 resip::Timer::T4 = 10 * T1; 00034 00035 unsigned long 00036 resip::Timer::T100 = 80; 00037 00038 unsigned long 00039 resip::Timer::TB = 64*T1; 00040 00041 unsigned long 00042 resip::Timer::TD = 32000; 00043 00044 unsigned long 00045 resip::Timer::TC = 3*60*1000; 00046 00047 unsigned long 00048 resip::Timer::TF = 64*T1; 00049 00050 unsigned long 00051 resip::Timer::TH = 64*T1; 00052 00053 unsigned long 00054 resip::Timer::TS = 32000; 00055 00056 void 00057 Timer::resetT1(unsigned long t1) 00058 { 00059 T1 = t1; 00060 T2 = 8 * T1; 00061 T4 = 10 * T1; 00062 TB = 64*T1; 00063 TF = 64*T1; 00064 TH = 64*T1; 00065 } 00066 00067 Data 00068 Timer::toData(Type timer) 00069 { 00070 switch (timer) 00071 { 00072 case TimerA: // doubling 00073 return "Timer A"; 00074 case TimerB: 00075 return "Timer B"; 00076 case TimerC: 00077 return "Timer C"; 00078 case TimerD: 00079 return "Timer D"; 00080 case TimerE1: 00081 return "Timer E1"; 00082 case TimerE2: 00083 return "Timer E2"; 00084 case TimerF: 00085 return "Timer F"; 00086 case TimerG: 00087 return "Timer G"; 00088 case TimerH: 00089 return "Timer H"; 00090 case TimerI: 00091 return "Timer I"; 00092 case TimerJ: 00093 return "Timer J"; 00094 case TimerK: 00095 return "Timer K"; 00096 case TimerTrying: 00097 return "Timer Trying"; 00098 case TimerStaleClient: 00099 return "Timer StaleClient"; 00100 case TimerStaleServer: 00101 return "Timer StaleServer"; 00102 case TimerStateless: 00103 return "Timer Stateless"; 00104 case TimerCleanUp: 00105 return "Timer Cleanup"; 00106 default: 00107 assert(0); 00108 } 00109 return "Bad Bad Bad in timer"; 00110 } 00111 00112 00113 TransactionTimer::TransactionTimer(unsigned long ms, 00114 Timer::Type type, 00115 const Data& transactionId) : 00116 mWhen(ms + Timer::getTimeMs()), 00117 mType(type), 00118 mTransactionId(transactionId), 00119 mDuration(ms) 00120 {} 00121 00122 std::ostream& 00123 TransactionTimer::encode(std::ostream& str) const 00124 { 00125 UInt64 now(Timer::getTimeMs()); 00126 str << "TransactionTimer[ when=" << mWhen << " rel="; 00127 if (mWhen < now) 00128 { 00129 str << "past"; 00130 } 00131 else 00132 { 00133 str << (mWhen - now); 00134 } 00135 str << "]"; 00136 return str; 00137 } 00138 00139 #ifndef RESIP_USE_STL_STREAMS 00140 EncodeStream& 00141 TransactionTimer::encode(EncodeStream& str) const 00142 { 00143 UInt64 now(Timer::getTimeMs()); 00144 str << "TransactionTimer[ when=" << mWhen << " rel="; 00145 if (mWhen < now) 00146 { 00147 str << "past"; 00148 } 00149 else 00150 { 00151 str << (mWhen - now); 00152 } 00153 str << "]"; 00154 return str; 00155 } 00156 #endif 00157 00158 TimerWithPayload::TimerWithPayload(unsigned long ms, Message* message) : 00159 mWhen(ms + Timer::getTimeMs()), 00160 mMessage(message) 00161 { 00162 assert(mMessage); 00163 } 00164 00165 std::ostream& 00166 TimerWithPayload::encode(std::ostream& str) const 00167 { 00168 UInt64 now(Timer::getTimeMs()); 00169 str << "TimerWithPayload[ when=" << mWhen << " rel="; 00170 if (mWhen < now) 00171 { 00172 str << "past"; 00173 } 00174 else 00175 { 00176 str << (mWhen - now); 00177 } 00178 str << "]"; 00179 return str; 00180 } 00181 00182 #ifndef RESIP_USE_STL_STREAMS 00183 EncodeStream& 00184 TimerWithPayload::encode(EncodeStream& str) const 00185 { 00186 UInt64 now(Timer::getTimeMs()); 00187 str << "TimerWithPayload[ when=" << mWhen << " rel="; 00188 if (mWhen < now) 00189 { 00190 str << "past"; 00191 } 00192 else 00193 { 00194 str << (mWhen - now); 00195 } 00196 str << "]"; 00197 return str; 00198 } 00199 #endif 00200 00201 00202 /* ==================================================================== 00203 * The Vovida Software License, Version 1.0 00204 * 00205 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00206 * 00207 * Redistribution and use in source and binary forms, with or without 00208 * modification, are permitted provided that the following conditions 00209 * are met: 00210 * 00211 * 1. Redistributions of source code must retain the above copyright 00212 * notice, this list of conditions and the following disclaimer. 00213 * 00214 * 2. Redistributions in binary form must reproduce the above copyright 00215 * notice, this list of conditions and the following disclaimer in 00216 * the documentation and/or other materials provided with the 00217 * distribution. 00218 * 00219 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00220 * and "Vovida Open Communication Application Library (VOCAL)" must 00221 * not be used to endorse or promote products derived from this 00222 * software without prior written permission. For written 00223 * permission, please contact vocal@vovida.org. 00224 * 00225 * 4. Products derived from this software may not be called "VOCAL", nor 00226 * may "VOCAL" appear in their name, without prior written 00227 * permission of Vovida Networks, Inc. 00228 * 00229 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00230 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00231 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00232 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00233 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00234 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00235 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00236 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00237 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00238 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00239 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00240 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00241 * DAMAGE. 00242 * 00243 * ==================================================================== 00244 * 00245 * This software consists of voluntary contributions made by Vovida 00246 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00247 * Inc. For more information on Vovida Networks, Inc., please see 00248 * <http://www.vovida.org/>. 00249 * 00250 */
1.7.5.1