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.

191 lines
4.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1996, Microsoft Corporation.
  4. //
  5. // File: wqpend.hxx
  6. //
  7. // Contents: WEB Query pending queue class
  8. //
  9. // History: 96/Apr/12 dlee Created
  10. //
  11. //----------------------------------------------------------------------------
  12. #pragma once
  13. //+---------------------------------------------------------------------------
  14. //
  15. // Class: CWebPendingItem
  16. //
  17. // Purpose: A single pending query item, including the security content
  18. // and the extension control block containing the query
  19. // parameters.
  20. //
  21. // History: 96/Jul/9 DwightKr Created
  22. //
  23. //----------------------------------------------------------------------------
  24. class CWebPendingItem
  25. {
  26. public:
  27. CWebPendingItem() : _pEcb(0),
  28. _hSecurityToken(INVALID_HANDLE_VALUE)
  29. {
  30. }
  31. CWebPendingItem( EXTENSION_CONTROL_BLOCK * pEcb,
  32. HANDLE hSecurityToken ) : _pEcb(pEcb),
  33. _hSecurityToken(hSecurityToken)
  34. {
  35. }
  36. ~CWebPendingItem()
  37. {
  38. Cleanup();
  39. }
  40. void Cleanup()
  41. {
  42. if ( INVALID_HANDLE_VALUE != _hSecurityToken )
  43. {
  44. CloseHandle( _hSecurityToken );
  45. _hSecurityToken = INVALID_HANDLE_VALUE;
  46. _pEcb = 0;
  47. }
  48. }
  49. HANDLE AcquireSecurityToken()
  50. {
  51. HANDLE hSecurityToken = _hSecurityToken;
  52. _hSecurityToken = INVALID_HANDLE_VALUE;
  53. return hSecurityToken;
  54. }
  55. void Acquire( CWebPendingItem & item )
  56. {
  57. item = *this;
  58. _pEcb = 0;
  59. AcquireSecurityToken();
  60. }
  61. CWebPendingItem & operator = (CWebPendingItem & src)
  62. {
  63. _pEcb = src._pEcb;
  64. _hSecurityToken = src._hSecurityToken;
  65. return *this;
  66. }
  67. EXTENSION_CONTROL_BLOCK * GetEcb() const { return _pEcb; }
  68. HANDLE GetSecurityToken() const { return _hSecurityToken; }
  69. private:
  70. EXTENSION_CONTROL_BLOCK * _pEcb;
  71. HANDLE _hSecurityToken;
  72. };
  73. //+---------------------------------------------------------------------------
  74. //
  75. // Class: CWebPendingQueue
  76. //
  77. // Purpose: A queue for pending query requests that couldn't be
  78. // serviced because we didn't want the web server to keep
  79. // making new threads
  80. //
  81. // History: 96/Apr/12 dlee Created
  82. //
  83. //----------------------------------------------------------------------------
  84. class CWebPendingQueue : public TFifoCircularQueue<CWebPendingItem>
  85. {
  86. public:
  87. CWebPendingQueue();
  88. ~CWebPendingQueue()
  89. {
  90. Win4Assert( !Any() && "Destructor: pending queue must be empty");
  91. }
  92. void Shutdown()
  93. {
  94. CWebPendingItem item;
  95. while ( AcquireTop(item) )
  96. {
  97. CWebServer webServer( item.GetEcb() );
  98. webServer.SetHttpStatus( HTTP_STATUS_SERVER_ERROR );
  99. webServer.ReleaseSession( HSE_STATUS_ERROR );
  100. item.Cleanup();
  101. }
  102. Win4Assert( !Any() && "Shutdown: pending queue must be empty");
  103. }
  104. private:
  105. ULONG _ulSignature;
  106. };
  107. //+---------------------------------------------------------------------------
  108. //
  109. // Class: CWebResourceArbiter
  110. //
  111. // Purpose: Keeps track of the # of concurrent threads to determine
  112. // when to start queueing query requests.
  113. //
  114. // History: 96/Apr/12 dlee Created
  115. //
  116. //----------------------------------------------------------------------------
  117. class CWebResourceArbiter
  118. {
  119. public:
  120. CWebResourceArbiter();
  121. void AddThread() { InterlockedIncrement( &_cThreads ); }
  122. void RemoveThread() { InterlockedDecrement( &_cThreads ); }
  123. BOOL IsSystemBusy();
  124. LONG GetThreadCount() const { return _cThreads; }
  125. private:
  126. ULONG _ulSignature;
  127. LONG _cThreads;
  128. LONG _maxThreads;
  129. unsigned _maxPendingQueries;
  130. };
  131. //+---------------------------------------------------------------------------
  132. //
  133. // Class: CIncomingThread
  134. //
  135. // Purpose: Bumps the thread refcount on CWebResourceArbiter
  136. //
  137. // History: 96/Apr/12 dlee Created
  138. //
  139. //----------------------------------------------------------------------------
  140. class CIncomingThread
  141. {
  142. public:
  143. CIncomingThread( CWebResourceArbiter & arbiter ) : _arbiter( arbiter )
  144. {
  145. arbiter.AddThread();
  146. END_CONSTRUCTION( CIncomingThread );
  147. }
  148. ~CIncomingThread()
  149. {
  150. _arbiter.RemoveThread();
  151. }
  152. private:
  153. CWebResourceArbiter & _arbiter;
  154. };