00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <cabal_waiter.h>
00022 #include <cabal_os.h>
00023 namespace Cabal
00024 {
00025
00026 void Waiter::usedBandwidth( const long int bytes )
00027 {
00028
00029 if ( m_bandwidth == 0 ) return;
00030
00031
00032 MSECS curTime = Net::timeOfDay();
00033
00034 MSECS timeLapse;
00035 if ( m_lastSentTime < 0 )
00036 timeLapse = 0;
00037 else
00038 timeLapse = curTime < m_lastSentTime ?
00039 CABAL_DAY_LENGTH - m_lastSentTime + curTime :
00040 curTime - m_lastSentTime;
00041
00042
00043 MSECS usedTime = m_lastSentSize * 1000 / m_bandwidth;
00044 if ( usedTime > timeLapse ) {
00045
00046 m_lastSentSize = (m_bandwidth / ( usedTime - timeLapse ) ) + bytes + 1;
00047 }
00048 else
00049 m_lastSentSize = bytes;
00050
00051
00052 m_lastSentTime = curTime;
00053
00054 }
00055
00056 MSECS Waiter::minimalWait()
00057 {
00058
00059 if ( m_bandwidth == 0 ) return 0;
00060
00061
00062 MSECS curTime = Net::timeOfDay();
00063 MSECS timeLapse ;
00064 if ( m_lastSentTime < 0 )
00065 timeLapse = 0;
00066 else
00067 timeLapse = curTime < m_lastSentTime ?
00068 CABAL_DAY_LENGTH - m_lastSentTime + curTime :
00069 curTime - m_lastSentTime;
00070
00071
00072 long int bytesGone = m_bandwidth * timeLapse / 1000;
00073
00074
00075 if ( m_lastSentSize <= bytesGone ) {
00076 return 0;
00077 }
00078
00079
00080 return static_cast<MSECS>( (m_lastSentSize - bytesGone) * 1000 / m_bandwidth );
00081 }
00082
00083 }
00084
00085