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.

531 lines
10 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. dsocket.h
  9. Abstract:
  10. This header defines the "DSOCKET" class. The DSOCKET class defines state
  11. variables and operations for DSOCKET objects within the WinSock 2 DLL. A
  12. DSOCKET object represents all of the information that the WinSock 2 DLL
  13. knows about a socket created using the Windows Sockets API.
  14. Author:
  15. Paul Drews (drewsxpa@ashland.intel.com) 30-June-1995
  16. Notes:
  17. $Revision: 1.12 $
  18. $Modtime: 08 Mar 1996 00:07:38 $
  19. Revision History:
  20. most-recent-revision-date email-name
  21. description
  22. 07-14-1995 dirk@mink.intel.com
  23. Moved member function descriptions to the implementation file
  24. dsocket.cpp
  25. 07-09-1995 drewsxpa@ashland.intel.com
  26. Completed first complete version with clean compile and released for
  27. subsequent implementation.
  28. 07-08-95 drewsxpa@ashland.intel.com
  29. Original version
  30. --*/
  31. #ifndef _DSOCKET_
  32. #define _DSOCKET_
  33. #include "winsock2.h"
  34. #include <windows.h>
  35. #include "classfwd.h"
  36. #include "ws2help.h"
  37. class DSOCKET: private WSHANDLE_CONTEXT
  38. {
  39. public:
  40. static
  41. INT
  42. DSocketClassInitialize();
  43. static
  44. INT
  45. DSocketClassCleanup();
  46. static
  47. INT
  48. AddSpecialApiReference(
  49. IN SOCKET SocketHandle
  50. );
  51. static
  52. PDSOCKET
  53. GetCountedDSocketFromSocket(
  54. IN SOCKET SocketHandle
  55. );
  56. static
  57. PDSOCKET
  58. GetCountedDSocketFromSocketNoExport(
  59. IN SOCKET SocketHandle
  60. );
  61. DSOCKET();
  62. INT
  63. Initialize(
  64. IN PPROTO_CATALOG_ITEM CatalogEntry
  65. );
  66. ~DSOCKET();
  67. SOCKET
  68. GetSocketHandle();
  69. PDPROVIDER
  70. GetDProvider();
  71. DWORD_PTR
  72. GetContext();
  73. VOID
  74. SetContext(
  75. IN DWORD_PTR Context
  76. );
  77. PPROTO_CATALOG_ITEM
  78. GetCatalogItem();
  79. INT
  80. AssociateSocketHandle(
  81. IN SOCKET SocketHandle,
  82. IN BOOLEAN ProviderSocket
  83. );
  84. INT
  85. DisassociateSocketHandle( );
  86. VOID
  87. AddDSocketReference(
  88. );
  89. VOID
  90. DropDSocketReference(
  91. );
  92. VOID
  93. DestroyDSocket(
  94. );
  95. BOOL
  96. IsProviderSocket(
  97. );
  98. BOOL
  99. IsApiSocket (
  100. );
  101. BOOL
  102. IsOverlappedSocket (
  103. );
  104. #ifndef WS2_DEBUGGER_EXTENSION
  105. //
  106. // Give debugger extension access to all fields
  107. //
  108. private:
  109. #endif
  110. static
  111. PDSOCKET
  112. FindIFSSocket (
  113. IN SOCKET SocketHandle
  114. );
  115. friend class DPROCESS;
  116. static LPCONTEXT_TABLE sm_context_table;
  117. // Context tables
  118. //#define m_reference_count RefCount
  119. //#define m_socket_handle Handle
  120. DWORD_PTR m_handle_context;
  121. // The uninterpreted socket handle context value that was set by
  122. // SetContext at the time of WPUCreateSocketHandle.
  123. PDPROVIDER m_provider;
  124. // Reference to the DPROVIDER object representing the service provider
  125. // that controls this socket.
  126. PPROTO_CATALOG_ITEM m_catalog_item;
  127. // The protocol catalog item used to create this socket
  128. BOOLEAN m_pvd_socket;
  129. // TRUE if this socket comes from the provider and not created by
  130. // helper DLL on provider request (WPUCreateSocketHandle).
  131. BOOLEAN m_api_socket;
  132. // TRUE if socket was returned via socket/WSASocketA/WSASocketW call,
  133. // or imported from IFS provider in other API calls
  134. // FALSE for sockets that are used only at SPI level (created on
  135. // request from layered provider and never exposed to the
  136. // application)
  137. BOOLEAN m_overlapped_socket;
  138. // To support the hack of creations of non-overlapped handles
  139. // during Accept and JoinLeaf by handle helper.
  140. #if defined(DEBUG_TRACING) || defined(WS2_DEBUGGER_EXTENSION)
  141. #define SOCKET_STACK_BACKTRACE_DEPTH 2
  142. public:
  143. PVOID m_CreatorBackTrace[SOCKET_STACK_BACKTRACE_DEPTH];
  144. // Socket creator information
  145. #endif
  146. }; // class DSOCKET
  147. inline SOCKET
  148. DSOCKET::GetSocketHandle()
  149. /*++
  150. Routine Description:
  151. Retrieves the external socket-handle value corresponding to this internal
  152. DSOCKET object.
  153. Arguments:
  154. None
  155. Return Value:
  156. The corresponding external socket-handle value.
  157. --*/
  158. {
  159. return((SOCKET)Handle);
  160. }
  161. inline PDPROVIDER
  162. DSOCKET::GetDProvider()
  163. /*++
  164. Routine Description:
  165. Retrieves a reference to the DPROVIDER object associated with this DSOCKET
  166. object.
  167. Arguments:
  168. None
  169. Return Value:
  170. The reference to the DPROVIDER object associated with this DSOCKET object.
  171. --*/
  172. {
  173. return(m_provider);
  174. }
  175. inline DWORD_PTR
  176. DSOCKET::GetContext()
  177. /*++
  178. Routine Description:
  179. This function retrieves the socket handle context value set with the
  180. SetContext operation. This function is typically called at the time of
  181. WPUQuerySocketHandleContext. The return value is unspecified if SetContext
  182. has not been called.
  183. Arguments:
  184. None
  185. Return Value:
  186. Returns the context value that was set by SetContext. This value is
  187. uninterpreted by the WinSock 2 DLL.
  188. --*/
  189. {
  190. return(m_handle_context);
  191. }
  192. inline VOID
  193. DSOCKET::SetContext(
  194. IN DWORD_PTR Context
  195. )
  196. /*++
  197. Routine Description:
  198. This function sets the socket handle context value. This function is
  199. typically called at the time of WPUCreateSocketHandle.
  200. Arguments:
  201. lpContext - Supplies the uninterpreted socket handle context value to be
  202. associated with this socket.
  203. Return Value:
  204. None
  205. --*/
  206. {
  207. m_handle_context = Context;
  208. }
  209. inline PPROTO_CATALOG_ITEM
  210. DSOCKET::GetCatalogItem()
  211. /*++
  212. Routine Description:
  213. Retreives the pointer to the catalog item associated with this socket.
  214. Arguments:
  215. Return Value:
  216. The pointer to the catalog item associated with this socket.
  217. --*/
  218. {
  219. return(m_catalog_item);
  220. }
  221. inline
  222. BOOL
  223. DSOCKET::IsProviderSocket(
  224. )
  225. /*++
  226. Routine Description:
  227. This function returns a boolean indicating whether the object is
  228. for the socket created by the provider (presumably IFS).
  229. Arguments:
  230. None
  231. Return Value:
  232. TRUE - The object is for the socket created by the provider.
  233. FALSE - The object is for the socket created by helper DLL.
  234. --*/
  235. {
  236. return m_pvd_socket;
  237. } // IsProviderSocket
  238. inline
  239. BOOL
  240. DSOCKET::IsApiSocket(
  241. )
  242. /*++
  243. Routine Description:
  244. This function returns a boolean indicating whether the object represents
  245. socket used by API client.
  246. Arguments:
  247. None
  248. Return Value:
  249. TRUE - The socket is used by API client .
  250. FALSE - The object is used by SPI client.
  251. --*/
  252. {
  253. return m_api_socket;
  254. } // IsApiSocket
  255. inline
  256. BOOL
  257. DSOCKET::IsOverlappedSocket(
  258. )
  259. /*++
  260. Routine Description:
  261. This function returns a boolean indicating whether the object represents
  262. overlapped socket.
  263. Arguments:
  264. None
  265. Return Value:
  266. TRUE - The socket is overlapped.
  267. FALSE - The object is non-overlapped.
  268. --*/
  269. {
  270. return m_overlapped_socket;
  271. } // IsOverlappedSocket
  272. inline VOID
  273. DSOCKET::AddDSocketReference(
  274. )
  275. /*++
  276. Routine Description:
  277. Adds a reference to the DSOCKET.
  278. Arguments:
  279. None
  280. Return Value:
  281. None
  282. --*/
  283. {
  284. WahReferenceHandleContext(this);
  285. } // AddDSocketReference
  286. inline VOID
  287. DSOCKET::DropDSocketReference(
  288. )
  289. /*++
  290. Routine Description:
  291. Drops the DSOCKET reference and destroys the object
  292. if reference count is 0.
  293. Arguments:
  294. None
  295. Return Value:
  296. None
  297. --*/
  298. {
  299. if (WahDereferenceHandleContext(this)==0)
  300. DestroyDSocket ();
  301. } // DropDSocketReference
  302. inline
  303. PDSOCKET
  304. DSOCKET::GetCountedDSocketFromSocket(
  305. IN SOCKET SocketHandle
  306. )
  307. /*++
  308. Routine Description
  309. This procedure takes a client socket handle and maps it to a DSOCKET object
  310. reference. The reference is counted.
  311. If socket object corresponding to the handle cannot be found in the table
  312. this function queires all IFS providers to see if one of the recognizes
  313. the handle.
  314. Whenever this procedure successfuly returns a counted reference, it is the
  315. responsibility of the caller to eventually call DropDSocketReference.
  316. Note that this procedure assumes that the caller has already checked to
  317. make sure that WinSock is initialized.
  318. Arguments:
  319. SocketHandle - Supplies the client-level socket handle to be mapped.
  320. Return Value:
  321. DSOCKET object or NULL in case the object cannot be found
  322. --*/
  323. {
  324. PDSOCKET Socket;
  325. Socket = static_cast<PDSOCKET>(WahReferenceContextByHandle (
  326. sm_context_table,
  327. (HANDLE)SocketHandle));
  328. if (Socket!=NULL)
  329. return Socket;
  330. else
  331. return FindIFSSocket (SocketHandle);
  332. }
  333. inline
  334. PDSOCKET
  335. DSOCKET::GetCountedDSocketFromSocketNoExport(
  336. IN SOCKET SocketHandle
  337. )
  338. /*++
  339. Routine Description
  340. This procedure takes a client socket handle and maps it to a DSOCKET object
  341. reference. The reference is counted.
  342. No attempt is made to find IFS provider for the socket if it cannot be found
  343. in the table. This function is intented for calls from non-IFS providers
  344. such as in context of WPUQuerySocketHandleContext.
  345. Whenever this procedure successfuly returns a counted reference, it is the
  346. responsibility of the caller to eventually call DropDSocketReference.
  347. Note that this procedure assumes that the caller has already checked to
  348. make sure that WinSock is initialized.
  349. Arguments:
  350. SocketHandle - Supplies the client-level socket handle to be mapped.
  351. Return Value:
  352. DSOCKET object or NULL in case the object cannot be found
  353. --*/
  354. {
  355. return static_cast<PDSOCKET>(WahReferenceContextByHandle (
  356. sm_context_table,
  357. (HANDLE)SocketHandle));
  358. }
  359. #endif // _DSOCKET_