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.

472 lines
15 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999-2000 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/98 jtk Created
  13. * 02/11/2000 jtk Derived from IODAta.h
  14. ***************************************************************************/
  15. #include "dnmdmi.h"
  16. #undef DPF_SUBCOMP
  17. #define DPF_SUBCOMP DN_SUBCOMP_MODEM
  18. //**********************************************************************
  19. // Constant definitions
  20. //**********************************************************************
  21. //**********************************************************************
  22. // Macro definitions
  23. //**********************************************************************
  24. //**********************************************************************
  25. // Structure definitions
  26. //**********************************************************************
  27. //**********************************************************************
  28. // Variable definitions
  29. //**********************************************************************
  30. //**********************************************************************
  31. // Function prototypes
  32. //**********************************************************************
  33. //**********************************************************************
  34. // ------------------------------
  35. // CModemReadIOData::PoolAllocFunction - called when new CModemReadIOData is allocated
  36. //
  37. // Entry: Context (handle of read complete event)
  38. //
  39. // Exit: Boolean indicating success
  40. // TRUE = success
  41. // FALSE = failure
  42. // ------------------------------
  43. #undef DPF_MODNAME
  44. #define DPF_MODNAME "CModemReadIOData::PoolAllocFunction"
  45. BOOL CModemReadIOData::PoolAllocFunction( void* pvItem, void* pvContext )
  46. {
  47. BOOL fReturn;
  48. CModemReadIOData* pReadIOData = (CModemReadIOData*)pvItem;
  49. HANDLE hContext = (HANDLE)pvContext;
  50. //
  51. // initialize
  52. //
  53. fReturn = TRUE;
  54. pReadIOData->m_dwWin9xReceiveErrorReturn = ERROR_SUCCESS;
  55. pReadIOData->jkm_dwOverlappedBytesReceived = 0;
  56. pReadIOData->jkm_dwImmediateBytesReceived = 0;
  57. pReadIOData->m_ReadState = READ_STATE_UNKNOWN;
  58. pReadIOData->m_dwBytesToRead = 0;
  59. pReadIOData->m_dwReadOffset = 0;
  60. pReadIOData->m_lRefCount = 0;
  61. pReadIOData->m_pThreadPool = NULL;
  62. pReadIOData->m_Sig[0] = 'R';
  63. pReadIOData->m_Sig[1] = 'I';
  64. pReadIOData->m_Sig[2] = 'O';
  65. pReadIOData->m_Sig[3] = 'D';
  66. pReadIOData->m_OutstandingReadListLinkage.Initialize();
  67. memset( &pReadIOData->m_ReceiveBuffer, 0x00, sizeof( pReadIOData->m_ReceiveBuffer ) );
  68. #ifdef WIN95
  69. DNASSERT( pReadIOData->Win9xOperationPending() == FALSE );
  70. #endif // WIN95
  71. memset( &pReadIOData->m_SPReceivedBuffer, 0x00, sizeof( pReadIOData->m_SPReceivedBuffer ) );
  72. pReadIOData->m_SPReceivedBuffer.BufferDesc.pBufferData = &pReadIOData->m_ReceiveBuffer.ReceivedData[ sizeof( pReadIOData->m_ReceiveBuffer.MessageHeader ) ];
  73. // Initialize Base Class members
  74. #ifdef WINNT
  75. pReadIOData->m_NTIOOperationType = NT_IO_OPERATION_UNKNOWN;
  76. #endif // WINNT
  77. #ifdef WIN95
  78. pReadIOData->m_fWin9xOperationPending = FALSE;
  79. #endif // WIN95
  80. pReadIOData->m_pDataPort = NULL;
  81. memset( &pReadIOData->m_Overlap, 0x00, sizeof( pReadIOData->m_Overlap ) );
  82. //
  83. // set the appropriate callback
  84. //
  85. #ifdef WINNT
  86. //
  87. // WinNT, always use IO completion ports
  88. //
  89. DNASSERT( hContext == NULL );
  90. DNASSERT( pReadIOData->NTIOOperationType() == NT_IO_OPERATION_UNKNOWN );
  91. pReadIOData->SetNTIOOperationType( NT_IO_OPERATION_RECEIVE );
  92. #else // WIN95
  93. //
  94. // Win9x
  95. //
  96. DNASSERT( hContext != NULL );
  97. DNASSERT( pReadIOData->OverlapEvent() == NULL );
  98. #endif // WINNT
  99. return fReturn;
  100. }
  101. //**********************************************************************
  102. //**********************************************************************
  103. // ------------------------------
  104. // CModemReadIOData::PoolInitFunction - called when new item is grabbed from the pool
  105. //
  106. // Entry: Context (read complete event)
  107. //
  108. // Exit: Boolean indicating success
  109. // TRUE = success
  110. // FALSE = failure
  111. // ------------------------------
  112. #undef DPF_MODNAME
  113. #define DPF_MODNAME "CModemReadIOData::PoolInitFunction"
  114. void CModemReadIOData::PoolInitFunction( void* pvItem, void* pvContext )
  115. {
  116. CModemReadIOData* pReadIOData = (CModemReadIOData*)pvItem;
  117. HANDLE hContext = (HANDLE)pvContext;
  118. DNASSERT( pReadIOData->m_OutstandingReadListLinkage.IsEmpty() != FALSE );
  119. DNASSERT( pReadIOData->m_dwBytesToRead == 0 );
  120. DNASSERT( pReadIOData->m_dwReadOffset == 0 );
  121. DNASSERT( pReadIOData->jkm_dwOverlappedBytesReceived == 0 );
  122. DNASSERT( pReadIOData->m_SPReceivedBuffer.BufferDesc.pBufferData == &pReadIOData->m_ReceiveBuffer.ReceivedData[ sizeof( pReadIOData->m_ReceiveBuffer.MessageHeader ) ] );
  123. DNASSERT( pReadIOData->DataPort() == NULL );
  124. #ifdef WIN95
  125. DNASSERT( pReadIOData->Win9xOperationPending() == FALSE );
  126. pReadIOData->SetOverlapEvent( hContext );
  127. #endif // WIN95
  128. //
  129. // Initialize internal SPRECEIVEDDATA. When data is received, it's possible
  130. // that the pointers in the SPRECEIVEDDATA block were manipulated. Reset
  131. // them to reflect that the entire buffer is available.
  132. //
  133. ZeroMemory( &pReadIOData->m_SPReceivedBuffer, sizeof( pReadIOData->m_SPReceivedBuffer ) );
  134. pReadIOData->m_SPReceivedBuffer.BufferDesc.pBufferData = &pReadIOData->m_ReceiveBuffer.ReceivedData[ sizeof( pReadIOData->m_ReceiveBuffer.MessageHeader ) ];
  135. DNASSERT(pReadIOData->m_lRefCount == 0);
  136. pReadIOData->m_lRefCount = 1;
  137. }
  138. //**********************************************************************
  139. //**********************************************************************
  140. // ------------------------------
  141. // CModemReadIOData::PoolReleaseFunction - called when CModemReadIOData is returned to pool
  142. //
  143. // Entry: Nothing
  144. //
  145. // Exit: Nothing
  146. // ------------------------------
  147. #undef DPF_MODNAME
  148. #define DPF_MODNAME "CModemReadIOData::PoolReleaseFunction"
  149. void CModemReadIOData::PoolReleaseFunction( void* pvItem )
  150. {
  151. CModemReadIOData* pReadIOData = (CModemReadIOData*)pvItem;
  152. DNASSERT( pReadIOData->m_OutstandingReadListLinkage.IsEmpty() != FALSE );
  153. pReadIOData->m_ReadState = READ_STATE_UNKNOWN;
  154. pReadIOData->m_dwBytesToRead = 0;
  155. pReadIOData->m_dwReadOffset = 0;
  156. pReadIOData->jkm_dwOverlappedBytesReceived = 0;
  157. #ifdef WIN95
  158. DNASSERT( pReadIOData->Win9xOperationPending() == FALSE );
  159. pReadIOData->SetOverlapEvent( NULL );
  160. #endif // WIN95
  161. pReadIOData->SetDataPort( NULL );
  162. }
  163. //**********************************************************************
  164. //**********************************************************************
  165. // ------------------------------
  166. // CModemReadIOData::PoolDeallocFunction - called when CModemReadIOData is deallocated
  167. //
  168. // Entry: Nothing
  169. //
  170. // Exit: Nothing
  171. // ------------------------------
  172. #undef DPF_MODNAME
  173. #define DPF_MODNAME "CModemReadIOData::PoolDeallocFunction"
  174. void CModemReadIOData::PoolDeallocFunction( void* pvItem )
  175. {
  176. const CModemReadIOData* pReadIOData = (CModemReadIOData*)pvItem;
  177. DNASSERT( pReadIOData->m_OutstandingReadListLinkage.IsEmpty() != FALSE );
  178. DNASSERT( pReadIOData->m_dwBytesToRead == 0 );
  179. DNASSERT( pReadIOData->m_dwReadOffset == 0 );
  180. DNASSERT( pReadIOData->m_ReadState == READ_STATE_UNKNOWN );
  181. DNASSERT( pReadIOData->m_lRefCount == 0 );
  182. DNASSERT( pReadIOData->m_pThreadPool == NULL );
  183. DNASSERT( pReadIOData->DataPort() == NULL );
  184. #ifdef WIN95
  185. DNASSERT( pReadIOData->OverlapEvent() == NULL );
  186. DNASSERT( pReadIOData->Win9xOperationPending() == FALSE );
  187. #endif // WIN95
  188. }
  189. //**********************************************************************
  190. //**********************************************************************
  191. // ------------------------------
  192. // CRedaIOData::ReturnSelfToPool - return this item to the pool
  193. //
  194. // Entry: Nothing
  195. //
  196. // Exit: Nothing
  197. // ------------------------------
  198. #undef DPF_MODNAME
  199. #define DPF_MODNAME "CModemReadIOData::ReturnSelfToPool"
  200. void CModemReadIOData::ReturnSelfToPool( void )
  201. {
  202. CModemThreadPool *pThreadPool;
  203. DNASSERT( m_lRefCount == 0 );
  204. DNASSERT( m_pThreadPool != NULL );
  205. pThreadPool = m_pThreadPool;
  206. SetThreadPool( NULL );
  207. pThreadPool->ReturnReadIOData( this );
  208. }
  209. //**********************************************************************
  210. //**********************************************************************
  211. // ------------------------------
  212. // CModemWriteIOData::PoolAllocFunction - called when new CModemWriteIOData is allocated
  213. //
  214. // Entry: Context (handle of write completion event)
  215. //
  216. // Exit: Boolean indicating success
  217. // TRUE = allocation succeeded
  218. // FALSE = allocation failed
  219. //
  220. // Note: We always want a command structure associated with CModemWriteIOData
  221. // so we don't need to grab a new command from the command pool each
  222. // time a CModemWriteIOData entry is removed from its pool. This is done
  223. // for speed.
  224. // ------------------------------
  225. #undef DPF_MODNAME
  226. #define DPF_MODNAME "CModemWriteIOData::PoolAllocFunction"
  227. BOOL CModemWriteIOData::PoolAllocFunction( void* pvItem, void* pvContext )
  228. {
  229. BOOL fReturn;
  230. CModemCommandData *pCommand;
  231. CModemWriteIOData* pWriteIOData = (CModemWriteIOData*)pvItem;
  232. HANDLE hContext = (HANDLE)pvContext;
  233. #ifdef WIN95
  234. DNASSERT( hContext != NULL );
  235. #endif // WIN95
  236. pWriteIOData->m_pNext = NULL;
  237. pWriteIOData->m_pBuffers = NULL;
  238. pWriteIOData->m_uBufferCount = 0;
  239. pWriteIOData->m_pCommand = NULL;
  240. pWriteIOData->m_SendCompleteAction = SEND_COMPLETE_ACTION_UNKNOWN;
  241. pWriteIOData->jkm_hSendResult = DPN_OK;
  242. pWriteIOData->jkm_dwOverlappedBytesSent = 0;
  243. pWriteIOData->jkm_dwImmediateBytesSent = 0;
  244. pWriteIOData->m_Sig[0] = 'W';
  245. pWriteIOData->m_Sig[1] = 'I';
  246. pWriteIOData->m_Sig[2] = 'O';
  247. pWriteIOData->m_Sig[3] = 'D';
  248. pWriteIOData->m_OutstandingWriteListLinkage.Initialize();
  249. memset( &pWriteIOData->m_DataBuffer, 0x00, sizeof( pWriteIOData->m_DataBuffer ) );
  250. pWriteIOData->m_DataBuffer.MessageHeader.SerialSignature = SERIAL_HEADER_START;
  251. // Initialize Base Class members
  252. #ifdef WINNT
  253. pWriteIOData->m_NTIOOperationType = NT_IO_OPERATION_UNKNOWN;
  254. #endif // WINNT
  255. #ifdef WIN95
  256. pWriteIOData->m_fWin9xOperationPending = FALSE;
  257. #endif // WIN95
  258. pWriteIOData->m_pDataPort = NULL;
  259. memset( &pWriteIOData->m_Overlap, 0x00, sizeof( pWriteIOData->m_Overlap ) );
  260. //
  261. // initialize
  262. //
  263. fReturn = TRUE;
  264. pCommand = (CModemCommandData*)g_ModemCommandDataPool.Get();
  265. if ( pCommand == NULL )
  266. {
  267. DPFX(DPFPREP, 0, "Could not get command when allocating new CModemWriteIOData!" );
  268. fReturn = FALSE;
  269. goto Exit;
  270. }
  271. //
  272. // associate this command with the WriteData, clear the command descriptor
  273. // because the command isn't really being used yet, and it'll
  274. // cause an ASSERT when it's removed from the WriteIOData pool.
  275. //
  276. pWriteIOData->m_pCommand = pCommand;
  277. //
  278. // set the appropriate IO function
  279. //
  280. #ifdef WINNT
  281. //
  282. // WinNT, we'll always use completion ports
  283. //
  284. DNASSERT( pWriteIOData->NTIOOperationType() == NT_IO_OPERATION_UNKNOWN );
  285. pWriteIOData->SetNTIOOperationType( NT_IO_OPERATION_SEND );
  286. #else // WIN95
  287. //
  288. // Win9x
  289. //
  290. DNASSERT( pWriteIOData->OverlapEvent() == NULL );
  291. #endif // WINNT
  292. Exit:
  293. return fReturn;
  294. }
  295. //**********************************************************************
  296. //**********************************************************************
  297. // ------------------------------
  298. // CModemWriteIOData::PoolInitFunction - called when new CModemWriteIOData is removed from pool
  299. //
  300. // Entry: Nothing
  301. //
  302. // Exit: Boolean indicating success
  303. // TRUE = success
  304. // FALSE = failure
  305. // ------------------------------
  306. #undef DPF_MODNAME
  307. #define DPF_MODNAME "CModemWriteIOData::PoolInitFunction"
  308. void CModemWriteIOData::PoolInitFunction( void* pvItem, void* pvContext )
  309. {
  310. CModemWriteIOData* pWriteIOData = (CModemWriteIOData*)pvItem;
  311. HANDLE hContext = (HANDLE)pvContext;
  312. DNASSERT( pWriteIOData->m_pNext == NULL );
  313. DNASSERT( pWriteIOData->m_pBuffers == NULL );
  314. DNASSERT( pWriteIOData->m_uBufferCount == 0 );
  315. DNASSERT( pWriteIOData->jkm_dwOverlappedBytesSent == 0 );
  316. DNASSERT( pWriteIOData->m_pCommand != NULL );
  317. pWriteIOData->m_pCommand->SetDescriptor();
  318. DNASSERT( pWriteIOData->m_pCommand->GetDescriptor() != NULL_DESCRIPTOR );
  319. DNASSERT( pWriteIOData->m_pCommand->GetUserContext() == NULL );
  320. DNASSERT( pWriteIOData->m_SendCompleteAction == SEND_COMPLETE_ACTION_UNKNOWN );
  321. DNASSERT( pWriteIOData->m_OutstandingWriteListLinkage.IsEmpty() != FALSE );
  322. DNASSERT( pWriteIOData->DataPort() == NULL );
  323. #ifdef WIN95
  324. DNASSERT( pWriteIOData->Win9xOperationPending() == FALSE );
  325. pWriteIOData->SetOverlapEvent( hContext );
  326. #endif // WIN95
  327. }
  328. //**********************************************************************
  329. //**********************************************************************
  330. // ------------------------------
  331. // CModemWriteIOData::PoolReleaseFunction - called when CModemWriteIOData is returned to pool
  332. //
  333. // Entry: Nothing
  334. //
  335. // Exit: Nothing
  336. // ------------------------------
  337. #undef DPF_MODNAME
  338. #define DPF_MODNAME "CModemWriteIOData::PoolReleaseFunction"
  339. void CModemWriteIOData::PoolReleaseFunction( void* pvItem )
  340. {
  341. CModemWriteIOData* pWriteIOData = (CModemWriteIOData*)pvItem;
  342. DNASSERT( pWriteIOData->m_pCommand != NULL );
  343. pWriteIOData->m_pCommand->Reset();
  344. DNASSERT( pWriteIOData->m_OutstandingWriteListLinkage.IsEmpty() != FALSE );
  345. #ifdef WIN95
  346. DNASSERT( pWriteIOData->Win9xOperationPending() == FALSE );
  347. pWriteIOData->SetOverlapEvent( NULL );
  348. #endif
  349. pWriteIOData->m_pBuffers = NULL;
  350. pWriteIOData->m_uBufferCount = 0;
  351. pWriteIOData->jkm_dwOverlappedBytesSent = 0;
  352. pWriteIOData->m_pNext = NULL;
  353. pWriteIOData->m_SendCompleteAction = SEND_COMPLETE_ACTION_UNKNOWN;
  354. pWriteIOData->SetDataPort( NULL );
  355. DEBUG_ONLY( memset( &pWriteIOData->m_DataBuffer.Data[ 1 ], 0x00, sizeof( pWriteIOData->m_DataBuffer.Data ) - 1 ) );
  356. }
  357. //**********************************************************************
  358. //**********************************************************************
  359. // ------------------------------
  360. // CModemWriteIOData::PoolDeallocFunction - called when new CModemWriteIOData is deallocated
  361. //
  362. // Entry: Nothing
  363. //
  364. // Exit: Nothing
  365. // ------------------------------
  366. #undef DPF_MODNAME
  367. #define DPF_MODNAME "CModemWriteIOData::PoolDeallocFunction"
  368. void CModemWriteIOData::PoolDeallocFunction( void* pvItem )
  369. {
  370. CModemWriteIOData* pWriteIOData = (CModemWriteIOData*)pvItem;
  371. DNASSERT( pWriteIOData->m_pBuffers == NULL );
  372. DNASSERT( pWriteIOData->m_uBufferCount == 0 );
  373. DNASSERT( pWriteIOData->m_SendCompleteAction == SEND_COMPLETE_ACTION_UNKNOWN );
  374. DNASSERT( pWriteIOData->m_OutstandingWriteListLinkage.IsEmpty() != FALSE );
  375. DNASSERT( pWriteIOData->m_DataBuffer.MessageHeader.SerialSignature == SERIAL_HEADER_START );
  376. DNASSERT( pWriteIOData->m_pCommand != NULL );
  377. pWriteIOData->m_pCommand->DecRef();
  378. pWriteIOData->m_pCommand = NULL;
  379. DNASSERT( pWriteIOData->DataPort() == NULL );
  380. #ifdef WIN95
  381. DNASSERT( pWriteIOData->OverlapEvent() == NULL );
  382. DNASSERT( pWriteIOData->Win9xOperationPending() == FALSE );
  383. #endif // WIN95
  384. }
  385. //**********************************************************************