Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.3 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: IdleStat.h
  4. //
  5. // Module: CMMON32.EXE
  6. //
  7. // Synopsis: Definition for the CIdleStatistics class to handle Idle Disconnect
  8. //
  9. // Copyright (c) 1996-1998 Microsoft Corporation
  10. //
  11. // Author: quintinb Created Header 08/16/99
  12. //
  13. //+----------------------------------------------------------------------------
  14. #ifndef IDLESTAT_H
  15. #define IDLESTAT_H
  16. #include "SmplRing.h"
  17. //+---------------------------------------------------------------------------
  18. //
  19. // class CIdleStatistics
  20. //
  21. // Description: A class to handle idle disconnect
  22. // After Start(), call UpdateEveryInterval(dwTraffic) for every
  23. // interval, every second. Then use IsIdle() and IsIdleTimeout()
  24. // to tell whether it is currently idle and whether the idle
  25. // timeout is reached.
  26. // Note, this class will only handle one direction traffic
  27. // (read or write)
  28. //
  29. // History: fengsun Created 10/1/97
  30. //
  31. //----------------------------------------------------------------------------
  32. class CIdleStatistics
  33. {
  34. public:
  35. CIdleStatistics();
  36. void Start(DWORD dwThreshold, DWORD dwTimeOut); // start the idle statistics
  37. void Stop(); // Stop the idle statistics
  38. BOOL IsStarted() const; // Whether the idle statistics is started
  39. // return FALSE if Start() is not called
  40. // or Stop() is called
  41. void Reset(); // reset idle start time to 0
  42. BOOL IsIdle() const; // Whether the connection is currently idle
  43. BOOL IsIdleTimeout() const; // Whether the idle timeout is reached
  44. void UpdateEveryInterval(DWORD dwTraffic); // This function is called every second
  45. protected:
  46. enum {IDLE_INTERVAL = 60L*1000L }; // 1 minute for idle disconnect time period
  47. enum {IDLE_MONITOR_DATA_POINTS = IDLE_INTERVAL/1000}; // every second
  48. DWORD m_dwTimeOut; // Timeout time in miniseconds
  49. DWORD m_dwThreshold; // The threshold, if the traffic in last minute
  50. // is below threshold, it is considered idle
  51. DWORD m_dwStartIdleTime; // The start time when the connection is idle,
  52. // or 0 if not currently idle
  53. CSimpleRing<DWORD, IDLE_MONITOR_DATA_POINTS> m_DataPointsRing; // A 60 point DWORD data array
  54. public:
  55. #ifdef DEBUG
  56. void AssertValid() const;
  57. #endif
  58. };
  59. //
  60. // Inline functions
  61. //
  62. inline CIdleStatistics::CIdleStatistics()
  63. {
  64. m_dwTimeOut = m_dwThreshold = m_dwStartIdleTime = 0;
  65. }
  66. inline void CIdleStatistics::Reset()
  67. {
  68. m_dwStartIdleTime = 0;
  69. m_DataPointsRing.Reset();
  70. }
  71. inline void CIdleStatistics::Stop()
  72. {
  73. m_dwTimeOut = 0;
  74. }
  75. inline BOOL CIdleStatistics::IsStarted() const
  76. {
  77. return m_dwTimeOut != 0;
  78. }
  79. inline BOOL CIdleStatistics::IsIdle() const
  80. {
  81. return IsStarted() && (m_dwStartIdleTime != 0);
  82. }
  83. inline BOOL CIdleStatistics::IsIdleTimeout() const
  84. {
  85. return IsIdle() &&
  86. ( (GetTickCount() - m_dwStartIdleTime) > m_dwTimeOut);
  87. }
  88. #endif