Source code of Windows XP (NT5)
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.

142 lines
2.7 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1997 **/
  4. /**********************************************************************/
  5. /*
  6. main.cxx
  7. Library initialization for rpcref.dll --
  8. This Dll adds a ref count around the RPC runtime call -
  9. RpcServerListen(). This enables multiple services in
  10. the inetinfo process to do a RpcServerListen() without
  11. stomping over each other.
  12. This Dll will maintain a ref count on calls to RpcServerListen()
  13. and call RpcMgmtStopServerListening() when the ref count goes to 0.
  14. FILE HISTORY:
  15. RajeevR 18-Aug-1997 Created.
  16. */
  17. #include <windows.h>
  18. #include <stdio.h>
  19. extern "C" {
  20. #include <rpc.h>
  21. };
  22. #include <pudebug.h>
  23. DWORD cRefs = 0;
  24. CRITICAL_SECTION csCritRef;
  25. extern "C"
  26. BOOL WINAPI DLLEntry( HINSTANCE hDll, DWORD dwReason, LPVOID lpvReserved )
  27. {
  28. BOOL fReturn = TRUE;
  29. switch ( dwReason )
  30. {
  31. case DLL_PROCESS_ATTACH:
  32. cRefs = 0;
  33. INITIALIZE_CRITICAL_SECTION( &csCritRef );
  34. break;
  35. case DLL_PROCESS_DETACH:
  36. DeleteCriticalSection( &csCritRef );
  37. break;
  38. case DLL_THREAD_ATTACH:
  39. case DLL_THREAD_DETACH:
  40. default:
  41. break ;
  42. }
  43. return ( fReturn);
  44. } // main()
  45. DWORD
  46. InetinfoStartRpcServerListen(
  47. VOID
  48. )
  49. /*++
  50. Routine Description:
  51. This function starts RpcServerListen for this process. The first
  52. service that is calling this function will actually start the
  53. RpcServerListen, subsequent calls just bump a ref count
  54. Arguments:
  55. None.
  56. Return Value:
  57. None.
  58. --*/
  59. {
  60. RPC_STATUS Status = RPC_S_OK;
  61. EnterCriticalSection( &csCritRef );
  62. if( cRefs++ == 0 ) {
  63. Status = RpcServerListen(
  64. 1, // minimum num threads.
  65. RPC_C_LISTEN_MAX_CALLS_DEFAULT, // max concurrent calls.
  66. TRUE ); // don't wait
  67. }
  68. LeaveCriticalSection( &csCritRef );
  69. return( Status );
  70. }
  71. DWORD
  72. InetinfoStopRpcServerListen(
  73. VOID
  74. )
  75. /*++
  76. Routine Description:
  77. Bump ref count down. Last caller will do actual cleanup.
  78. Arguments:
  79. None.
  80. Return Value:
  81. None.
  82. --*/
  83. {
  84. RPC_STATUS Status = RPC_S_OK;
  85. EnterCriticalSection( &csCritRef );
  86. if( --cRefs == 0 ) {
  87. Status = RpcMgmtStopServerListening(0);
  88. //
  89. // wait for all RPC threads to go away.
  90. //
  91. if( Status == RPC_S_OK) {
  92. Status = RpcMgmtWaitServerListen();
  93. }
  94. }
  95. LeaveCriticalSection( &csCritRef );
  96. return( Status );
  97. }