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.

283 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. pipedata.hxx
  5. Abstract:
  6. Encapsulation of message passing over named pipes.
  7. IPM_MESSAGEs are delivered messages from the other side of the pipe
  8. IPM_MESSAGE_ACCEPTORs is the interface clients of this API must implement
  9. IPM_MESSAGE_PIPE is the creation, deletion, and write interface for this API
  10. Threading:
  11. It is valid to call the API on any thread
  12. Callbacks can occur on an NT thread, or on the thread that was calling into the API.
  13. Author:
  14. Jeffrey Wall (jeffwall) 9/12/2001
  15. Revision History:
  16. --*/
  17. #ifndef _PIPEDATA_HXX_
  18. #define _PIPEDATA_HXX_
  19. //
  20. // When starting in backward compatibility mode, we use a well known pipe name
  21. //
  22. #define WEB_ADMIN_SERVICE_INETINFO_PIPENAME L"\\\\.\\pipe\\iisipm14acf167-60fe-4c1d-8563-f209abaa8f4b"
  23. enum IPM_WP_SHUTDOWN_MSG;
  24. //
  25. // IPM opcodes
  26. //
  27. // **********************************
  28. // These must be kept in synch with the METADATA for the opcodes below.
  29. // **********************************
  30. //
  31. enum IPM_OPCODE
  32. {
  33. IPM_OP_MINIMUM = 0,
  34. IPM_OP_PING,
  35. IPM_OP_PING_REPLY,
  36. IPM_OP_WORKER_REQUESTS_SHUTDOWN,
  37. IPM_OP_SHUTDOWN,
  38. IPM_OP_REQUEST_COUNTERS,
  39. IPM_OP_SEND_COUNTERS,
  40. IPM_OP_PERIODIC_PROCESS_RESTART_PERIOD_IN_MINUTES,
  41. IPM_OP_PERIODIC_PROCESS_RESTART_MEMORY_USAGE_IN_KB,
  42. IPM_OP_PERIODIC_PROCESS_RESTART_SCHEDULE,
  43. IPM_OP_GETPID,
  44. IPM_OP_HRESULT,
  45. IPM_OP_MAXIMUM
  46. };
  47. struct IPM_OPCODE_METADATA
  48. {
  49. size_t sizeMaximumAndRequiredSize;
  50. BOOL fServerSideExpectsThisMessage;
  51. };
  52. IPM_OPCODE_METADATA IPM_OP_DATA_SIZE [] = {
  53. { 0, FALSE }, //IPM_OP_MINIMUM
  54. { 0, FALSE }, //IPM_OP_PING
  55. { 0, TRUE }, //IPM_OP_PING_REPLY
  56. { sizeof(IPM_WP_SHUTDOWN_MSG), TRUE }, //IPM_OP_WORKER_REQUESTS_SHUTDOWN
  57. { sizeof(BOOL), FALSE }, // IPM_OP_SHUTDOWN
  58. { 0, FALSE }, //IPM_OP_REQUEST_COUNTERS
  59. { MAXLONG, TRUE }, //IPM_OP_SEND_COUNTERS
  60. { sizeof(DWORD), FALSE }, //IPM_OP_PERIODIC_PROCESS_RESTART_PERIOD_IN_MINUTES
  61. { 2 * sizeof(DWORD), FALSE }, //IPM_OP_PERIODIC_PROCESS_RESTART_MEMORY_USAGE_IN_KB
  62. { MAXLONG, FALSE }, //IPM_OP_PERIODIC_PROCESS_RESTART_SCHEDULE
  63. { sizeof(DWORD), TRUE }, //IPM_OP_GETPID
  64. { sizeof(HRESULT), TRUE }, //IPM_OP_HRESULT
  65. { 0, FALSE } //IPM_OP_MAXIMUM
  66. };
  67. //
  68. // Data sent on a IPM_OP_WORKER_REQUESTS_SHUTDOWN message, to give the
  69. // reason for the message.
  70. //
  71. enum IPM_WP_SHUTDOWN_MSG
  72. {
  73. IPM_WP_MINIMUM = 0,
  74. IPM_WP_RESTART_COUNT_REACHED,
  75. IPM_WP_IDLE_TIME_REACHED,
  76. IPM_WP_RESTART_SCHEDULED_TIME_REACHED,
  77. IPM_WP_RESTART_ELAPSED_TIME_REACHED,
  78. IPM_WP_RESTART_VIRTUAL_MEMORY_LIMIT_REACHED,
  79. IPM_WP_RESTART_ISAPI_REQUESTED_RECYCLE,
  80. IPM_WP_RESTART_PRIVATE_BYTES_LIMIT_REACHED,
  81. IPM_WP_MAXIMUM
  82. };
  83. //
  84. // forward declarations and export directives
  85. //
  86. class dllexp IPM_MESSAGE_PIPE;
  87. class IPM_MESSAGE_IMP;
  88. //
  89. // There is one implementation of this interface (IPM_MESSAGE_IMP)
  90. //
  91. // The implementation is not exposed here because it has many more
  92. // public methods (ex: SetData) that are not needed by MESSAGE_ACCEPTORs
  93. // and serve only to confuse the data abstraction being exposed.
  94. //
  95. class IPM_MESSAGE
  96. {
  97. public:
  98. //
  99. // returns the IPM_OPCODE associated with this message
  100. //
  101. virtual IPM_OPCODE GetOpcode() const = 0;
  102. //
  103. // returns the data length of the message
  104. //
  105. virtual DWORD GetDataLen() const = 0;
  106. //
  107. // returns a pointer to the data of the message
  108. //
  109. virtual const BYTE * GetData() const = 0;
  110. }; // IPM_MESSAGE
  111. //
  112. // Users of this pipe mechanism are required to implement this interface
  113. // to receive pipe event callbacks.
  114. //
  115. // These callbacks will occur on NT Thread Pool threads, or sometimes
  116. // on the same thread that was used in a call to any MESSAGE_PIPE
  117. // instance
  118. //
  119. class IPM_MESSAGE_ACCEPTOR
  120. {
  121. public:
  122. //
  123. // Called when an IPM_MESSAGE is received on the pipe
  124. //
  125. virtual VOID AcceptMessage(IN CONST IPM_MESSAGE * pMessage) = 0;
  126. //
  127. // Called when the pipe is ready to read and write data
  128. //
  129. virtual VOID PipeConnected() = 0;
  130. //
  131. // Called when the pipe is no longer connected
  132. //
  133. virtual VOID PipeDisconnected(IN HRESULT Error) = 0;
  134. //
  135. // Called when an invalid message has arrived from the other side of the pipe
  136. //
  137. virtual VOID PipeMessageInvalid() = 0;
  138. }; // IPM_MESSAGE_ACCEPTOR
  139. //
  140. // interface to pipe mechanism.
  141. //
  142. class IPM_MESSAGE_PIPE
  143. {
  144. private:
  145. IPM_MESSAGE_PIPE();
  146. ~IPM_MESSAGE_PIPE();
  147. public:
  148. // Create returns a IPM_MESSAGE_PIPE for use
  149. static
  150. HRESULT
  151. CreateIpmMessagePipe(IPM_MESSAGE_ACCEPTOR * pAcceptor, // callback class
  152. LPCWSTR pszPipeName, // name of pipe
  153. BOOL fServerSide, // TRUE for CreateNamedPipe, FALSE for CreateFile
  154. PSECURITY_ATTRIBUTES pSa, // security attributes to apply to pipe
  155. IPM_MESSAGE_PIPE ** ppPipe); // outgoing pipe
  156. // Destroy disconnects the IPM_MESSAGE_PIPE, blocks until all work is finished, and deletes the IPM_MESSAGE_PIPE
  157. VOID
  158. DestroyIpmMessagePipe();
  159. // WriteMessage places a message on the pipe
  160. HRESULT
  161. WriteMessage(IPM_OPCODE opcode,
  162. DWORD dwDataLen,
  163. LPVOID pbData);
  164. //
  165. // The following functions are not for public consumption.
  166. // If you abuse them, I'll take them away.
  167. //
  168. BOOL
  169. IsValid();
  170. VOID IpmMessageCreated(IPM_MESSAGE_IMP *);
  171. VOID IpmMessageDeleted(IPM_MESSAGE_IMP *);
  172. // Register wait callback function
  173. static
  174. VOID
  175. CALLBACK
  176. MessagePipeCompletion(LPVOID pvoid,
  177. BOOLEAN TimerOrWaitFired);
  178. private:
  179. DWORD m_dwSignature;
  180. // handle to NT pipe
  181. HANDLE m_hPipe;
  182. // callback pointer
  183. IPM_MESSAGE_ACCEPTOR * m_pAcceptor;
  184. // TRUE if CreateNamedPipe was called, otherwise FALSE;
  185. BOOL m_fServerSide;
  186. // count of # of outstanding messages
  187. LONG m_cMessages;
  188. // list of outstanding messages
  189. LIST_ENTRY m_listHead;
  190. //
  191. // synchronization for list
  192. //
  193. CRITICAL_SECTION m_critSec;
  194. //
  195. // to be able to tell if initialization of critsec completed successfully
  196. //
  197. BOOL m_fCritSecInitialized;
  198. //
  199. // Saved failed disconnect hresult, just in case
  200. // the hresult can't be communicated immediately.
  201. //
  202. HRESULT m_hrDisconnect;
  203. //
  204. // Number of outstanding current users of the m_pAcceptor variable
  205. //
  206. ULONG m_cAcceptorUseCount;
  207. // safely increment m_cAcceptorUseCount
  208. VOID
  209. IncrementAcceptorInUse();
  210. // safely decrement m_cAcceptorUseCount and if appropriate, call NotifyPipeDisconnected
  211. VOID
  212. DecrementAcceptorInUse();
  213. // Issue a read for a given size
  214. HRESULT
  215. ReadMessage(DWORD dwReadSize);
  216. // Notify the IPM_MESSAGE_ACCEPTOR exactly once that an error has occurred
  217. VOID
  218. NotifyPipeDisconnected(HRESULT hrError);
  219. }; // IPM_MESSAGE_PIPE
  220. #endif // _PIPEDATA_HXX_