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.

435 lines
11 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: Connection.h
  6. * Content: Connection Object Header File
  7. *@@BEGIN_MSINTERNAL
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 02/29/00 mjn Created
  12. * 04/08/00 mjn Added ServiceProvider to Connection object
  13. * 04/18/00 mjn CConnection tracks connection status better
  14. * 06/22/00 mjn Replaced MakeConnecting(), MakeConnected(), MakeDisconnecting(), MakeInvalid() with SetStatus()
  15. * 07/20/00 mjn Modified CConnection::Disconnect()
  16. * 07/28/00 mjn Added send queue info structures
  17. * mjn Added m_bilinkConnections to CConnection
  18. * 08/05/00 RichGr IA64: Use %p format specifier in DPFs for 32/64-bit pointers and handles.
  19. * 08/09/00 mjn Added m_bilinkIndicated to CConnection
  20. * 02/12/01 mjn Added m_bilinkCallbackThreads,m_dwThreadCount,m_pThreadEvent to track threads using m_hEndPt
  21. * 05/17/01 mjn Remove unused flags
  22. *@@END_MSINTERNAL
  23. *
  24. ***************************************************************************/
  25. #ifndef __CONNECTION_H__
  26. #define __CONNECTION_H__
  27. #undef DPF_SUBCOMP
  28. #define DPF_SUBCOMP DN_SUBCOMP_CORE
  29. //**********************************************************************
  30. // Constant definitions
  31. //**********************************************************************
  32. #define CONNECTION_FLAG_LOCAL 0x00000001
  33. #ifndef DPNBUILD_NOMULTICAST
  34. #define CONNECTION_FLAG_MULTICAST_SENDER 0x00000010
  35. #define CONNECTION_FLAG_MULTICAST_RECEIVER 0x00000020
  36. #endif // DPNBUILD_NOMULTICAST
  37. //**********************************************************************
  38. // Macro definitions
  39. //**********************************************************************
  40. //**********************************************************************
  41. // Structure definitions
  42. //**********************************************************************
  43. typedef enum
  44. {
  45. INVALID,
  46. CONNECTING,
  47. CONNECTED,
  48. DISCONNECTING
  49. } CONNECTION_STATUS;
  50. typedef struct _USER_SEND_QUEUE_INFO
  51. {
  52. DWORD dwNumOutstanding;
  53. DWORD dwBytesOutstanding;
  54. } USER_SEND_QUEUE_INFO;
  55. class CCallbackThread;
  56. class CServiceProvider;
  57. class CSyncEvent;
  58. typedef struct _DIRECTNETOBJECT DIRECTNETOBJECT;
  59. //**********************************************************************
  60. // Variable definitions
  61. //**********************************************************************
  62. //**********************************************************************
  63. // Function prototypes
  64. //**********************************************************************
  65. //**********************************************************************
  66. // Class prototypes
  67. //**********************************************************************
  68. // class for RefCount buffer
  69. class CConnection
  70. {
  71. public:
  72. #undef DPF_MODNAME
  73. #define DPF_MODNAME "CConnection::FPMAlloc"
  74. static BOOL FPMAlloc( void* pvItem, void* pvContext )
  75. {
  76. CConnection* pConnection = (CConnection*)pvItem;
  77. pConnection->m_Sig[0] = 'C';
  78. pConnection->m_Sig[1] = 'O';
  79. pConnection->m_Sig[2] = 'N';
  80. pConnection->m_Sig[3] = 'N';
  81. if (!DNInitializeCriticalSection(&pConnection->m_cs))
  82. {
  83. return(FALSE);
  84. }
  85. DebugSetCriticalSectionRecursionCount(&pConnection->m_cs,0);
  86. pConnection->m_bilinkConnections.Initialize();
  87. pConnection->m_bilinkIndicated.Initialize();
  88. pConnection->m_bilinkCallbackThreads.Initialize();
  89. #ifndef DPNBUILD_NOMULTICAST
  90. pConnection->m_bilinkMulticast.Initialize();
  91. #endif // ! DPNBUILD_NOMULTICAST
  92. return(TRUE);
  93. };
  94. #undef DPF_MODNAME
  95. #define DPF_MODNAME "CConnection::FPMInitialize"
  96. static void FPMInitialize( void* pvItem, void* pvContext )
  97. {
  98. CConnection* pConnection = (CConnection*)pvItem;
  99. pConnection->m_pdnObject = static_cast<DIRECTNETOBJECT*>(pvContext);
  100. pConnection->m_dwFlags = 0;
  101. pConnection->m_lRefCount = 1;
  102. pConnection->m_hEndPt = NULL;
  103. pConnection->m_dpnid = 0;
  104. pConnection->m_pvContext = NULL;
  105. pConnection->m_pSP = NULL;
  106. pConnection->m_Status = INVALID;
  107. pConnection->m_dwThreadCount = 0;
  108. pConnection->m_pThreadEvent = NULL;
  109. //
  110. // Queue info
  111. //
  112. pConnection->m_QueueInfoHigh.dwNumOutstanding = 0;
  113. pConnection->m_QueueInfoHigh.dwBytesOutstanding = 0;
  114. pConnection->m_QueueInfoNormal.dwNumOutstanding = 0;
  115. pConnection->m_QueueInfoNormal.dwBytesOutstanding = 0;
  116. pConnection->m_QueueInfoLow.dwNumOutstanding = 0;
  117. pConnection->m_QueueInfoLow.dwBytesOutstanding = 0;
  118. DNASSERT(pConnection->m_bilinkConnections.IsEmpty());
  119. DNASSERT(pConnection->m_bilinkIndicated.IsEmpty());
  120. DNASSERT(pConnection->m_bilinkCallbackThreads.IsEmpty());
  121. #ifndef DPNBUILD_NOMULTICAST
  122. DNASSERT(pConnection->m_bilinkMulticast.IsEmpty());
  123. #endif // ! DPNBUILD_NOMULTICAST
  124. };
  125. #undef DPF_MODNAME
  126. #define DPF_MODNAME "CConnection::FPMRelease"
  127. static void FPMRelease( void* pvItem )
  128. {
  129. const CConnection* pConnection = (CConnection*)pvItem;
  130. DNASSERT(pConnection->m_bilinkConnections.IsEmpty());
  131. DNASSERT(pConnection->m_bilinkIndicated.IsEmpty());
  132. DNASSERT(pConnection->m_bilinkCallbackThreads.IsEmpty());
  133. #ifndef DPNBUILD_NOMULTICAST
  134. DNASSERT(pConnection->m_bilinkMulticast.IsEmpty());
  135. #endif // ! DPNBUILD_NOMULTICAST
  136. };
  137. #undef DPF_MODNAME
  138. #define DPF_MODNAME "CConnection::FPMDealloc"
  139. static void FPMDealloc( void* pvItem )
  140. {
  141. CConnection* pConnection = (CConnection*)pvItem;
  142. DNDeleteCriticalSection(&pConnection->m_cs);
  143. };
  144. void CConnection::ReturnSelfToPool( void );
  145. #undef DPF_MODNAME
  146. #define DPF_MODNAME "CConnection::AddRef"
  147. void AddRef(void)
  148. {
  149. LONG lRefCount;
  150. DNASSERT(m_lRefCount > 0);
  151. lRefCount = DNInterlockedIncrement(const_cast<LONG*>(&m_lRefCount));
  152. DPFX(DPFPREP, 3,"Connection::AddRef [0x%p] RefCount [0x%lx]",this,lRefCount);
  153. };
  154. void CConnection::Release(void);
  155. void Lock( void )
  156. {
  157. DNEnterCriticalSection( &m_cs );
  158. };
  159. void Unlock( void )
  160. {
  161. DNLeaveCriticalSection( &m_cs );
  162. };
  163. void SetEndPt(const HANDLE hEndPt)
  164. {
  165. m_hEndPt = hEndPt;
  166. };
  167. HRESULT CConnection::GetEndPt(HANDLE *const phEndPt,CCallbackThread *const pCallbackThread);
  168. void CConnection::ReleaseEndPt(CCallbackThread *const pCallbackThread);
  169. void SetStatus( const CONNECTION_STATUS status )
  170. {
  171. m_Status = status;
  172. };
  173. BOOL IsConnecting( void ) const
  174. {
  175. if (m_Status == CONNECTING)
  176. return( TRUE );
  177. return( FALSE );
  178. };
  179. BOOL IsConnected( void ) const
  180. {
  181. if (m_Status == CONNECTED)
  182. return( TRUE );
  183. return( FALSE );
  184. };
  185. BOOL IsDisconnecting( void ) const
  186. {
  187. if (m_Status == DISCONNECTING)
  188. return( TRUE );
  189. return( FALSE );
  190. };
  191. BOOL IsInvalid( void ) const
  192. {
  193. if (m_Status == INVALID)
  194. return( TRUE );
  195. return( FALSE );
  196. };
  197. void SetDPNID(const DPNID dpnid)
  198. {
  199. m_dpnid = dpnid;
  200. };
  201. DPNID GetDPNID(void) const
  202. {
  203. return(m_dpnid);
  204. };
  205. void SetContext( void *const pvContext )
  206. {
  207. m_pvContext = pvContext;
  208. };
  209. void *GetContext( void ) const
  210. {
  211. return( m_pvContext );
  212. };
  213. #undef DPF_MODNAME
  214. #define DPF_MODNAME "CConnection::MakeLocal"
  215. void MakeLocal(void)
  216. {
  217. DNASSERT(m_hEndPt == NULL);
  218. m_dwFlags |= CONNECTION_FLAG_LOCAL;
  219. };
  220. BOOL IsLocal(void) const
  221. {
  222. if (m_dwFlags & CONNECTION_FLAG_LOCAL)
  223. {
  224. return(TRUE);
  225. }
  226. return(FALSE);
  227. };
  228. #ifndef DPNBUILD_NOMULTICAST
  229. void MakeMulticastSender( void )
  230. {
  231. m_dwFlags |= CONNECTION_FLAG_MULTICAST_SENDER;
  232. };
  233. BOOL IsMulticastSender( void ) const
  234. {
  235. if (m_dwFlags & CONNECTION_FLAG_MULTICAST_SENDER)
  236. {
  237. return( TRUE );
  238. }
  239. return( FALSE);
  240. };
  241. void MakeMulticastReceiver( void )
  242. {
  243. m_dwFlags |= CONNECTION_FLAG_MULTICAST_RECEIVER;
  244. };
  245. BOOL IsMulticastReceiver( void ) const
  246. {
  247. if (m_dwFlags & CONNECTION_FLAG_MULTICAST_RECEIVER)
  248. {
  249. return( TRUE );
  250. }
  251. return( FALSE);
  252. };
  253. #endif // DPNBUILD_NOMULTICAST
  254. void CConnection::SetSP( CServiceProvider *const pSP );
  255. CServiceProvider *GetSP( void ) const
  256. {
  257. return( m_pSP );
  258. };
  259. void SetThreadCount( const DWORD dwCount )
  260. {
  261. m_dwThreadCount = dwCount;
  262. };
  263. void SetThreadEvent( CSyncEvent *const pSyncEvent )
  264. {
  265. m_pThreadEvent = pSyncEvent;
  266. };
  267. void CConnection::Disconnect(void);
  268. void CConnection::AddToHighQueue( const DWORD dwBytes )
  269. {
  270. m_QueueInfoHigh.dwNumOutstanding++;
  271. m_QueueInfoHigh.dwBytesOutstanding += dwBytes;
  272. };
  273. void CConnection::AddToNormalQueue( const DWORD dwBytes )
  274. {
  275. m_QueueInfoNormal.dwNumOutstanding++;
  276. m_QueueInfoNormal.dwBytesOutstanding += dwBytes;
  277. };
  278. void CConnection::AddToLowQueue( const DWORD dwBytes )
  279. {
  280. m_QueueInfoLow.dwNumOutstanding++;
  281. m_QueueInfoLow.dwBytesOutstanding += dwBytes;
  282. };
  283. void CConnection::RemoveFromHighQueue( const DWORD dwBytes )
  284. {
  285. m_QueueInfoHigh.dwNumOutstanding--;
  286. m_QueueInfoHigh.dwBytesOutstanding -= dwBytes;
  287. };
  288. void CConnection::RemoveFromNormalQueue( const DWORD dwBytes )
  289. {
  290. m_QueueInfoNormal.dwNumOutstanding--;
  291. m_QueueInfoNormal.dwBytesOutstanding -= dwBytes;
  292. };
  293. void CConnection::RemoveFromLowQueue( const DWORD dwBytes )
  294. {
  295. m_QueueInfoLow.dwNumOutstanding--;
  296. m_QueueInfoLow.dwBytesOutstanding -= dwBytes;
  297. };
  298. DWORD CConnection::GetHighQueueNum( void ) const
  299. {
  300. return( m_QueueInfoHigh.dwNumOutstanding );
  301. };
  302. DWORD CConnection::GetHighQueueBytes( void ) const
  303. {
  304. return( m_QueueInfoHigh.dwBytesOutstanding );
  305. };
  306. DWORD CConnection::GetNormalQueueNum( void ) const
  307. {
  308. return( m_QueueInfoNormal.dwNumOutstanding );
  309. };
  310. DWORD CConnection::GetNormalQueueBytes( void ) const
  311. {
  312. return( m_QueueInfoNormal.dwBytesOutstanding );
  313. };
  314. DWORD CConnection::GetLowQueueNum( void ) const
  315. {
  316. return( m_QueueInfoLow.dwNumOutstanding );
  317. };
  318. DWORD CConnection::GetLowQueueBytes( void ) const
  319. {
  320. return( m_QueueInfoLow.dwBytesOutstanding );
  321. };
  322. CBilink m_bilinkConnections;
  323. CBilink m_bilinkIndicated; // Indicated connections without DPNID's (players entries)
  324. CBilink m_bilinkCallbackThreads;
  325. #ifndef DPNBUILD_NOMULTICAST
  326. CBilink m_bilinkMulticast; // Multicast receive connections
  327. #endif // ! DPNBUILD_NOMULTICAST
  328. private:
  329. BYTE m_Sig[4];
  330. DWORD volatile m_dwFlags;
  331. LONG volatile m_lRefCount;
  332. HANDLE volatile m_hEndPt;
  333. DPNID m_dpnid;
  334. void * volatile m_pvContext;
  335. CServiceProvider *m_pSP;
  336. CONNECTION_STATUS m_Status;
  337. DWORD volatile m_dwThreadCount;
  338. CSyncEvent *m_pThreadEvent;
  339. USER_SEND_QUEUE_INFO m_QueueInfoHigh;
  340. USER_SEND_QUEUE_INFO m_QueueInfoNormal;
  341. USER_SEND_QUEUE_INFO m_QueueInfoLow;
  342. DIRECTNETOBJECT *m_pdnObject;
  343. #ifndef DPNBUILD_ONLYONETHREAD
  344. DNCRITICAL_SECTION m_cs;
  345. #endif // !DPNBUILD_ONLYONETHREAD
  346. };
  347. #undef DPF_MODNAME
  348. #endif // __CONNECTION_H__