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.

251 lines
8.1 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1998-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: IOData.cpp
  6. * Content: Functions for IO structures
  7. *
  8. *
  9. * History:
  10. * Date By Reason
  11. * ==== == ======
  12. * 11/25/1998 jtk Created
  13. * 02/11/2000 jtk Derived from IODAta.h
  14. ***************************************************************************/
  15. #include "dnwsocki.h"
  16. //**********************************************************************
  17. // Constant definitions
  18. //**********************************************************************
  19. //**********************************************************************
  20. // Macro definitions
  21. //**********************************************************************
  22. //**********************************************************************
  23. // Structure definitions
  24. //**********************************************************************
  25. //**********************************************************************
  26. // Variable definitions
  27. //**********************************************************************
  28. //**********************************************************************
  29. // Function prototypes
  30. //**********************************************************************
  31. //**********************************************************************
  32. // ------------------------------
  33. // CReadIOData::ReadIOData_Alloc - called when new CReadIOData is allocated
  34. //
  35. // Entry: Pointer to context
  36. //
  37. // Exit: Nothing
  38. // ------------------------------
  39. #undef DPF_MODNAME
  40. #define DPF_MODNAME "CReadIOData::ReadIOData_Alloc"
  41. BOOL CReadIOData::ReadIOData_Alloc( void* pvItem, void* pvContext )
  42. {
  43. BOOL fReturn;
  44. CSocketAddress *pSocketAddress;
  45. CReadIOData* pReadIOData = (CReadIOData*)pvItem;
  46. READ_IO_DATA_POOL_CONTEXT* pReadIOContext = (READ_IO_DATA_POOL_CONTEXT*)pvContext;
  47. DNASSERT( pvContext != NULL );
  48. //
  49. // initialize
  50. //
  51. fReturn = TRUE;
  52. pSocketAddress = NULL;
  53. pReadIOData->m_Sig[0] = 'R';
  54. pReadIOData->m_Sig[1] = 'I';
  55. pReadIOData->m_Sig[2] = 'O';
  56. pReadIOData->m_Sig[3] = 'D';
  57. #ifndef DPNBUILD_NOWINSOCK2
  58. pReadIOData->m_pOverlapped = NULL;
  59. pReadIOData->m_dwOverlappedBytesReceived = 0;
  60. #endif // ! DPNBUILD_NOWINSOCK2
  61. pReadIOData->m_pSocketPort = NULL;
  62. pReadIOData->m_dwBytesRead = 0;
  63. pReadIOData->m_ReceiveWSAReturn = ERROR_SUCCESS;
  64. DEBUG_ONLY( pReadIOData->m_fRetainedByHigherLayer = FALSE );
  65. pReadIOData->m_lRefCount = 0;
  66. pReadIOData->m_pThreadPool = NULL;
  67. DEBUG_ONLY( memset( &pReadIOData->m_ReceivedData, 0x00, sizeof( pReadIOData->m_ReceivedData ) ) );
  68. //
  69. // attempt to get a socket address for this item
  70. //
  71. #if ((defined(DPNBUILD_NOIPV6)) && (defined(DPNBUILD_NOIPX)))
  72. pSocketAddress = (CSocketAddress*) g_SocketAddressPool.Get((PVOID) ((DWORD_PTR) AF_INET));
  73. #else // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  74. pSocketAddress = (CSocketAddress*) g_SocketAddressPool.Get((PVOID) ((DWORD_PTR) pReadIOContext->sSPType));
  75. #endif // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  76. if ( pSocketAddress == NULL )
  77. {
  78. DPFX(DPFPREP, 0, "Problem allocating a new socket address when creating ReadIOData pool item" );
  79. fReturn = FALSE;
  80. goto Exit;
  81. }
  82. pReadIOData->m_pSourceSocketAddress = pSocketAddress;
  83. pReadIOData->m_iSocketAddressSize = pSocketAddress->GetAddressSize();
  84. Exit:
  85. return fReturn;
  86. }
  87. //**********************************************************************
  88. //**********************************************************************
  89. // ------------------------------
  90. // CReadIOData::ReadIOData_Get - called when new CReadIOData is removed from pool
  91. //
  92. // Entry: Pointer to context
  93. //
  94. // Exit: Nothing
  95. // ------------------------------
  96. #undef DPF_MODNAME
  97. #define DPF_MODNAME "CReadIOData::ReadIOData_Get"
  98. void CReadIOData::ReadIOData_Get( void* pvItem, void* pvContext )
  99. {
  100. DNASSERT( pvContext != NULL );
  101. CReadIOData* pReadIOData = (CReadIOData*)pvItem;
  102. READ_IO_DATA_POOL_CONTEXT* pReadIOContext = (READ_IO_DATA_POOL_CONTEXT*)pvContext;
  103. DNASSERT( pReadIOData->m_pSourceSocketAddress != NULL );
  104. DNASSERT( pReadIOData->m_iSocketAddressSize == pReadIOData->m_pSourceSocketAddress->GetAddressSize() );
  105. DNASSERT( pReadIOData->SocketPort() == NULL );
  106. DNASSERT( pReadIOContext->pThreadPool != NULL );
  107. DEBUG_ONLY( DNASSERT( pReadIOData->m_fRetainedByHigherLayer == FALSE ) );
  108. pReadIOData->m_pThreadPool = pReadIOContext->pThreadPool;
  109. #ifndef DPNBUILD_ONLYONEPROCESSOR
  110. DNASSERT(pReadIOContext->dwCPU != -1);
  111. pReadIOData->m_dwCPU = pReadIOContext->dwCPU;
  112. #endif // ! DPNBUILD_ONLYONEPROCESSOR
  113. #if ((! defined(DPNBUILD_NOIPV6)) || (! defined(DPNBUILD_NOIPX)))
  114. //
  115. // Make sure this address is for the right SP type, since this pooled read data
  116. // is possibly shared between them.
  117. //
  118. pReadIOData->m_pSourceSocketAddress->SetFamilyProtocolAndSize(pReadIOContext->sSPType);
  119. #endif // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  120. DNASSERT( pReadIOData->m_lRefCount == 0 );
  121. //
  122. // Initialize internal SPRECEIVEDDATA. When data is received, it's possible
  123. // that the pointers in the SPRECEIVEDDATA block were manipulated. Reset
  124. // them to reflect that the entire buffer is available.
  125. //
  126. ZeroMemory( &pReadIOData->m_SPReceivedBuffer, sizeof( pReadIOData->m_SPReceivedBuffer ) );
  127. pReadIOData->m_SPReceivedBuffer.BufferDesc.pBufferData = pReadIOData->m_ReceivedData;
  128. pReadIOData->m_SPReceivedBuffer.BufferDesc.dwBufferSize = sizeof( pReadIOData->m_ReceivedData );
  129. }
  130. //**********************************************************************
  131. //**********************************************************************
  132. // ------------------------------
  133. // CReadIOData::ReadIOData_Release - called when CReadIOData is returned to pool
  134. //
  135. // Entry: Nothing
  136. //
  137. // Exit: Nothing
  138. // ------------------------------
  139. #undef DPF_MODNAME
  140. #define DPF_MODNAME "CReadIOData::ReadIOData_Release"
  141. void CReadIOData::ReadIOData_Release( void* pvItem )
  142. {
  143. CReadIOData* pReadIOData = (CReadIOData*)pvItem;
  144. #ifndef DPNBUILD_NOWINSOCK2
  145. OVERLAPPED* pOverlapped;
  146. HRESULT hr;
  147. #endif // ! DPNBUILD_NOWINSOCK2
  148. DNASSERT( pReadIOData->m_lRefCount == 0 );
  149. DNASSERT( pReadIOData->m_pSourceSocketAddress != NULL );
  150. DEBUG_ONLY( DNASSERT( pReadIOData->m_fRetainedByHigherLayer == FALSE ) );
  151. #ifndef DPNBUILD_NOWINSOCK2
  152. pOverlapped = pReadIOData->GetOverlapped();
  153. if (pOverlapped != NULL)
  154. {
  155. pReadIOData->SetOverlapped( NULL );
  156. DNASSERT( pReadIOData->m_pThreadPool != NULL );
  157. DNASSERT( pReadIOData->m_pThreadPool->GetDPThreadPoolWork() != NULL );
  158. hr = IDirectPlay8ThreadPoolWork_ReleaseOverlapped(pReadIOData->m_pThreadPool->GetDPThreadPoolWork(),
  159. pOverlapped,
  160. 0);
  161. DNASSERT(hr == DPN_OK);
  162. }
  163. DNASSERT( pReadIOData->m_dwOverlappedBytesReceived == 0 );
  164. #endif // ! DPNBUILD_NOWINSOCK2
  165. pReadIOData->m_pThreadPool = NULL;
  166. pReadIOData->SetSocketPort( NULL );
  167. DEBUG_ONLY( memset( &pReadIOData->m_ReceivedData, 0x00, sizeof( pReadIOData->m_ReceivedData ) ) );
  168. }
  169. //**********************************************************************
  170. //**********************************************************************
  171. // ------------------------------
  172. // CReadIOData::ReadIOData_Dealloc - called when CReadIOData is deallocated
  173. //
  174. // Entry: Nothing
  175. //
  176. // Exit: Nothing
  177. // ------------------------------
  178. #undef DPF_MODNAME
  179. #define DPF_MODNAME "CReadIOData::ReadIOData_Dealloc"
  180. void CReadIOData::ReadIOData_Dealloc( void* pvItem )
  181. {
  182. CReadIOData* pReadIOData = (CReadIOData*)pvItem;
  183. DNASSERT( pReadIOData->m_lRefCount == 0 );
  184. DNASSERT( pReadIOData->m_pSourceSocketAddress != NULL );
  185. DEBUG_ONLY( DNASSERT( pReadIOData->m_fRetainedByHigherLayer == FALSE ) );
  186. DNASSERT( pReadIOData->m_pThreadPool == NULL );
  187. // Base Class
  188. DNASSERT( pReadIOData->SocketPort() == NULL );
  189. g_SocketAddressPool.Release(pReadIOData->m_pSourceSocketAddress);
  190. pReadIOData->m_pSourceSocketAddress = NULL;
  191. pReadIOData->m_iSocketAddressSize = 0;
  192. DNASSERT( pReadIOData->m_pSourceSocketAddress == NULL );
  193. }
  194. //**********************************************************************