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.

192 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name :
  4. AppPool.cxx
  5. Abstract:
  6. Defines the functions used to access the data channel.
  7. Author:
  8. Murali R. Krishnan ( MuraliK ) 20-Oct-1998
  9. Lei Jin ( leijin ) 13-Apr-1999 Porting
  10. Project:
  11. IIS Worker Process
  12. --*/
  13. #include "precomp.hxx"
  14. #include "AppPool.hxx"
  15. UL_APP_POOL::UL_APP_POOL(
  16. VOID
  17. ) : _hAppPool( NULL )
  18. {
  19. }
  20. UL_APP_POOL::~UL_APP_POOL(
  21. VOID
  22. )
  23. {
  24. Cleanup();
  25. }
  26. HRESULT
  27. UL_APP_POOL::Initialize(
  28. LPCWSTR pwszAppPoolName
  29. )
  30. /*++
  31. Routine Description:
  32. Initialize UL AppPool
  33. Arguments:
  34. pwszAppPoolName - AppPool Name
  35. Return Value:
  36. HRESULT
  37. --*/
  38. {
  39. ULONG rc;
  40. if ( _hAppPool != NULL )
  41. {
  42. DBGPRINTF(( DBG_CONTEXT,
  43. "AppPool already open!\n" ));
  44. return HRESULT_FROM_WIN32( ERROR_DUP_NAME );
  45. }
  46. _Lock.WriteLock();
  47. rc = HttpOpenAppPool( &_hAppPool,
  48. pwszAppPoolName,
  49. 0 );
  50. _Lock.WriteUnlock();
  51. if ( rc != NO_ERROR )
  52. {
  53. DBGPRINTF(( DBG_CONTEXT,
  54. "Failed to open AppPool '%ws'. rc = %d\n",
  55. pwszAppPoolName,
  56. rc ));
  57. return HRESULT_FROM_WIN32( rc );
  58. }
  59. return NO_ERROR;
  60. }
  61. HRESULT
  62. UL_APP_POOL::Cleanup(
  63. VOID
  64. )
  65. /*++
  66. Routine Description:
  67. Close data channel
  68. Arguments:
  69. None
  70. Return Value:
  71. HRESULT
  72. --*/
  73. {
  74. HRESULT hr = NO_ERROR;
  75. HANDLE hAppPool = NULL;
  76. bool fWriteLocked = false;
  77. DWORD dwSleepCount = 0;
  78. if ( _hAppPool != NULL )
  79. {
  80. fWriteLocked = _Lock.TryWriteLock();
  81. while ( !fWriteLocked )
  82. {
  83. dwSleepCount = !dwSleepCount;
  84. Sleep( dwSleepCount );
  85. fWriteLocked = _Lock.TryWriteLock();
  86. }
  87. hAppPool = _hAppPool;
  88. _hAppPool = NULL;
  89. _Lock.WriteUnlock();
  90. DBG_ASSERT( hAppPool != NULL );
  91. if ( !CloseHandle( hAppPool ) )
  92. {
  93. hr = HRESULT_FROM_WIN32( GetLastError() );
  94. }
  95. }
  96. return hr;
  97. }
  98. HANDLE
  99. UL_APP_POOL::QueryAndLockHandle(
  100. VOID
  101. )
  102. /*++
  103. Routine Description:
  104. Read locks and returns the handle.
  105. Arguments:
  106. None
  107. Return Value:
  108. HANDLE
  109. --*/
  110. {
  111. _Lock.ReadLock();
  112. return _hAppPool;
  113. }
  114. HRESULT
  115. UL_APP_POOL::UnlockHandle(
  116. VOID
  117. )
  118. /*++
  119. Routine Description:
  120. Read unlocks.
  121. Arguments:
  122. None
  123. Return Value:
  124. HRESULT
  125. --*/
  126. {
  127. DBG_ASSERT(_Lock.IsReadLocked());
  128. _Lock.ReadUnlock();
  129. return S_OK;
  130. }