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.

512 lines
11 KiB

  1. /*++
  2. Intel Corporation Proprietary Information
  3. Copyright (c) 1995 Intel Corporation
  4. This listing is supplied under the terms of a license agreement with
  5. Intel Corporation and may not be used, copied, nor disclosed except in
  6. accordance with the terms of that agreeement.
  7. Module Name:
  8. dprocess.h
  9. Abstract:
  10. This header defines the "DPROCESS" class. The DPROCESS class defines state
  11. variables and operations for DPROCESS objects within the WinSock 2 DLL. A
  12. DPROCESS object represents all of the information known about a process
  13. using the Windows Sockets API.
  14. Author:
  15. Paul Drews (drewsxpa@ashland.intel.com) 7-July-1995
  16. Notes:
  17. $Revision: 1.16 $
  18. $Modtime: 08 Mar 1996 04:58:14 $
  19. Revision History:
  20. most-recent-revision-date email-name
  21. description
  22. 25-July dirk@mink.intel.com
  23. Moved protocol catalog related items into DCATALOG. Added data
  24. member to contain a pointer to the protocol catalog. Removed
  25. provider list moved provider references to into the protocol
  26. catalog.
  27. 14-July-1995 dirk@mink.intel.com
  28. Moved member function documentation to implementation file
  29. dprocess.cpp. Changed critical section data members to be
  30. pointers to CRITICAL_SECTION. Added inline implementations for
  31. the list lock/unlock member functions.
  32. 07-09-1995 drewsxpa@ashland.intel.com
  33. Completed first complete version with clean compile and released for
  34. subsequent implementation.
  35. 7-July-1995 drewsxpa@ashland.intel.com
  36. Original version
  37. --*/
  38. #ifndef _DPROCESS_
  39. #define _DPROCESS_
  40. #include "winsock2.h"
  41. #include <windows.h>
  42. #include "ws2help.h"
  43. #include "classfwd.h"
  44. class DPROCESS
  45. {
  46. public:
  47. // Static (global-scope) member functions
  48. static PDPROCESS
  49. GetCurrentDProcess(
  50. VOID
  51. );
  52. static INT
  53. DProcessClassInitialize(
  54. VOID
  55. );
  56. // Normal member functions
  57. DPROCESS();
  58. INT Initialize();
  59. ~DPROCESS();
  60. BOOL
  61. DSocketDetach (
  62. IN LPWSHANDLE_CONTEXT Context
  63. );
  64. PDCATALOG
  65. GetProtocolCatalog();
  66. PNSCATALOG
  67. GetNamespaceCatalog();
  68. INT
  69. GetAsyncHelperDeviceID(
  70. OUT LPHANDLE HelperHandle
  71. );
  72. INT
  73. GetHandleHelperDeviceID(
  74. OUT LPHANDLE HelperHandle
  75. );
  76. INT
  77. GetNotificationHelperDeviceID(
  78. OUT LPHANDLE HelperHandle
  79. );
  80. VOID
  81. IncrementRefCount();
  82. DWORD
  83. DecrementRefCount();
  84. BYTE
  85. GetMajorVersion();
  86. BYTE
  87. GetMinorVersion();
  88. WORD
  89. GetVersion();
  90. VOID
  91. SetVersion( WORD Version );
  92. #ifndef WS2_DEBUGGER_EXTENSION
  93. //
  94. // Give debugger extension access to all fields
  95. //
  96. private:
  97. #endif
  98. VOID LockDThreadList();
  99. VOID UnLockDThreadList();
  100. VOID UpdateNamespaceCatalog ();
  101. INT
  102. OpenAsyncHelperDevice(
  103. OUT LPHANDLE HelperHandle
  104. );
  105. INT
  106. OpenHandleHelperDevice(
  107. OUT LPHANDLE HelperHandle
  108. );
  109. INT
  110. OpenNotificationHelperDevice(
  111. OUT LPHANDLE HelperHandle
  112. );
  113. static PDPROCESS sm_current_dprocess;
  114. // A class-scope reference to the single current DPROCESS object for this
  115. // process.
  116. LONG m_reference_count;
  117. // The number of times this object has been refereced by
  118. // WSAStarup/WSACleanup. WSAStartup increases the count and WSACleanup
  119. // decreases the count. Declarations for lists of associated objects:
  120. WORD m_version;
  121. // The WinSock version number for this process.
  122. BOOLEAN m_lock_initialized;
  123. // For proper cleanup of critical section if initialization fails
  124. PDCATALOG m_protocol_catalog;
  125. // Reference to the protocol catalog for the process
  126. HANDLE m_proto_catalog_change_event;
  127. // Event that keeps track of protocol catalog changes
  128. PNSCATALOG m_namespace_catalog;
  129. // Reference to the name space catalog for the process
  130. HANDLE m_ns_catalog_change_event;
  131. // Event that keeps track of name space catalog changes
  132. // Declarations for Helper objects created on demand:
  133. HANDLE m_ApcHelper;
  134. // Reference to the Asynchronous callback helper device. An asynchronous
  135. // callback helper device is only opened on demand.
  136. HANDLE m_HandleHelper;
  137. // Reference to the handle helper device. A handler
  138. // helper device is only opened on demand.
  139. HANDLE m_NotificationHelper;
  140. // Reference to the notification handle helper device. A notification
  141. // helper device is only opened on demand.
  142. #if 0
  143. // Thread list not used due to race conditions.
  144. // Lock is still used.
  145. LIST_ENTRY m_thread_list;
  146. #endif
  147. CRITICAL_SECTION m_thread_list_lock;
  148. }; // class DPROCESS
  149. inline
  150. PDPROCESS
  151. DPROCESS::GetCurrentDProcess(
  152. )
  153. /*++
  154. Routine Description:
  155. Retrieves a reference to the current DPROCESS object. Note that this is a
  156. "static" function with global scope instead of object-instance scope.
  157. Arguments:
  158. None
  159. Return Value:
  160. Returns pointer to current DPROCESS object or NULL if process has not been
  161. initialized yet
  162. --*/
  163. {
  164. return sm_current_dprocess;
  165. } //GetCurrentDProcess
  166. inline VOID
  167. DPROCESS::IncrementRefCount(
  168. VOID
  169. )
  170. /*++
  171. Routine Description:
  172. This function increases the reference count on this object.
  173. Arguments:
  174. Return Value:
  175. NONE
  176. --*/
  177. {
  178. InterlockedIncrement(&m_reference_count);
  179. }
  180. inline DWORD
  181. DPROCESS::DecrementRefCount(
  182. VOID
  183. )
  184. /*++
  185. Routine Description:
  186. This function decreases the reference count on this object.
  187. Arguments:
  188. Return Value:
  189. Returns the new value of the reference count
  190. --*/
  191. {
  192. return(InterlockedDecrement(&m_reference_count));
  193. }
  194. inline
  195. BYTE
  196. DPROCESS::GetMajorVersion()
  197. /*++
  198. Routine Description:
  199. This function returns the major WinSock version number negotiated
  200. at WSAStartup() time.
  201. Arguments:
  202. None.
  203. Return Value:
  204. Returns the major WinSock version number.
  205. --*/
  206. {
  207. assert(m_version != 0);
  208. return LOBYTE(m_version);
  209. } // GetMajorVersion
  210. inline
  211. BYTE
  212. DPROCESS::GetMinorVersion()
  213. /*++
  214. Routine Description:
  215. This function returns the minor WinSock version number negotiated
  216. at WSAStartup() time.
  217. Arguments:
  218. None.
  219. Return Value:
  220. Returns the minor WinSock version number.
  221. --*/
  222. {
  223. assert(m_version != 0);
  224. return HIBYTE(m_version);
  225. } // GetMinorVersion
  226. inline
  227. WORD
  228. DPROCESS::GetVersion()
  229. /*++
  230. Routine Description:
  231. This function returns the WinSock version number negotiated
  232. at WSAStartup() time.
  233. Arguments:
  234. None.
  235. Return Value:
  236. Returns the WinSock version number.
  237. --*/
  238. {
  239. assert(m_version != 0);
  240. return m_version;
  241. } // GetVersion
  242. inline VOID
  243. DPROCESS::LockDThreadList()
  244. /*++
  245. Routine Description:
  246. This function acquires mutually exclusive access to the list of DTHREAD
  247. objects attached to the DPROCESS object. The companion procedures
  248. LockDThreadList and UnLockDThreadList are used internally to bracket
  249. operations that add and remove items from the DTHREAD list.
  250. NOTE:
  251. Use a Critical Section object for best performance. Create the Critical
  252. Section object at DPROCESS object initialization time and destroy it at
  253. DPROCESS object destruction time.
  254. Arguments:
  255. None
  256. Return Value:
  257. None
  258. --*/
  259. {
  260. EnterCriticalSection(&m_thread_list_lock);
  261. }
  262. inline VOID
  263. DPROCESS::UnLockDThreadList()
  264. /*++
  265. Routine Description:
  266. This function releases mutually exclusive access to the list of DTHREAD
  267. objects attached to the DPROCESS object. The companion procedures
  268. LockDThreadList and UnLockDThreadList are used internally to bracket
  269. operations that add and remove items from the DTHREAD list.
  270. NOTE:
  271. Use a Critical Section object for best performance. Create the Critical
  272. Section object at DPROCESS object initialization time and destroy it at
  273. DPROCESS object destruction time.
  274. Arguments:
  275. None
  276. Return Value:
  277. None
  278. --*/
  279. {
  280. LeaveCriticalSection(&m_thread_list_lock);
  281. }
  282. inline INT
  283. DPROCESS::GetAsyncHelperDeviceID(
  284. OUT LPHANDLE HelperHandle
  285. )
  286. /*++
  287. Routine Description:
  288. Retrieves the opened Async Helper device ID required for processing
  289. callbacks in the overlapped I/O model. The operation opens the Async
  290. Helper device if necessary.
  291. Arguments:
  292. HelperHandle - Returns the requested Async Helper device ID.
  293. Return Value:
  294. The function returns ERROR_SUCESS if successful, otherwise it
  295. returns an appropriate WinSock error code.
  296. --*/
  297. {
  298. if (m_ApcHelper) {
  299. *HelperHandle = m_ApcHelper;
  300. return ERROR_SUCCESS;
  301. } //if
  302. else {
  303. return OpenAsyncHelperDevice (HelperHandle);
  304. }
  305. }
  306. inline INT
  307. DPROCESS::GetHandleHelperDeviceID(
  308. OUT LPHANDLE HelperHandle
  309. )
  310. /*++
  311. Routine Description:
  312. Retrieves the opened Handle Helper device ID required for allocation
  313. of socket handles for non-IFS providers. The operation opens the Handle
  314. Helper device if necessary.
  315. Arguments:
  316. HelperHandle - Returns the requested Handle Helper device ID.
  317. Return Value:
  318. The function returns ERROR_SUCESS if successful, otherwise it
  319. returns an appropriate WinSock error code.
  320. --*/
  321. {
  322. if (m_HandleHelper) {
  323. *HelperHandle = m_HandleHelper;
  324. return ERROR_SUCCESS;
  325. } //if
  326. else {
  327. return OpenHandleHelperDevice (HelperHandle);
  328. }
  329. }
  330. inline INT
  331. DPROCESS::GetNotificationHelperDeviceID(
  332. OUT LPHANDLE HelperHandle
  333. )
  334. /*++
  335. Routine Description:
  336. Retrieves the opened Async Helper device ID required for processing
  337. callbacks in the overlapped I/O model. The operation opens the Async
  338. Helper device if necessary.
  339. Arguments:
  340. HelperHandle - Returns the requested Async Helper device ID.
  341. Return Value:
  342. The function returns ERROR_SUCESS if successful, otherwise it
  343. returns an appropriate WinSock error code.
  344. --*/
  345. {
  346. if (m_NotificationHelper) {
  347. *HelperHandle = m_NotificationHelper;
  348. return ERROR_SUCCESS;
  349. } //if
  350. else {
  351. return OpenNotificationHelperDevice (HelperHandle);
  352. }
  353. }
  354. #endif // _DPROCESS_