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.

103 lines
2.9 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // EAPSessionTable.h
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file defines the class EAPSessionTable.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 01/15/1998 Original version.
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #ifndef _EAPSESSIONTABLE_H_
  19. #define _EAPSESSIONTABLE_H_
  20. #include <guard.h>
  21. #include <nocopy.h>
  22. #include <hashtbl.h>
  23. #include <list>
  24. #include <EAPSession.h>
  25. ///////////////////////////////////////////////////////////////////////////////
  26. //
  27. // CLASS
  28. //
  29. // EAPSessionTable
  30. //
  31. // DESCRIPTION
  32. //
  33. // This class maintains a collection of EAPSession objects indexed by
  34. // session ID. The table also enforces a sessionTimeout which is the
  35. // maximum time a session will be kept before being deleted.
  36. //
  37. ///////////////////////////////////////////////////////////////////////////////
  38. class EAPSessionTable
  39. : Guardable, NonCopyable
  40. {
  41. public:
  42. EAPSessionTable() throw (std::bad_alloc);
  43. ~EAPSessionTable();
  44. // Session timeout is specified in milliseconds.
  45. DWORD getSessionTimeout() const throw ();
  46. void setSessionTimeout(DWORD newVal) throw ();
  47. DWORD getMaxSessions() const throw ()
  48. { return maxSessions; }
  49. void setMaxSessions(DWORD newVal) throw ()
  50. { maxSessions = newVal; }
  51. // Clears and deletes all sessions.
  52. void clear();
  53. void insert(EAPSession* session);
  54. EAPSession* remove(DWORD key) throw ();
  55. protected:
  56. // Evicts all expired sessions.
  57. void evict(DWORDLONG now) throw ();
  58. // Evicts the oldest session.
  59. // Results are undefined if the session table is empty.
  60. void evictOldest() throw ();
  61. // List of (Session Expiry, Session) pairs. This list is kept sorted
  62. // by expiry and is used to evict expired sessions.
  63. typedef std::list < std::pair < DWORDLONG, EAPSession* > > SessionList;
  64. // A Session entry binds a SessionList iterator to a session. This allows
  65. // for efficient updating of the session list.
  66. typedef std::pair < EAPSession*, SessionList::iterator > SessionEntry;
  67. // Functor used for extracting the session ID from a SessionEntry.
  68. struct Extractor {
  69. DWORD operator()(const SessionEntry& entry) const throw ()
  70. { return entry.first->getID(); }
  71. };
  72. // Table of sessions indexed by session ID. Each entry also has an iterator
  73. // into the SessionList to allow for efficient removal.
  74. typedef hash_table < DWORD,
  75. identity<DWORD>,
  76. SessionEntry,
  77. Extractor
  78. > SessionTable;
  79. SessionList byExpiry;
  80. SessionTable byID;
  81. DWORDLONG sessionTimeout;
  82. DWORD maxSessions; // Max. number of active sessions.
  83. };
  84. #endif // _EAPSESSIONTABLE_H_