Source code of Windows XP (NT5)
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.

489 lines
11 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name :
  4. atqprocs.hxx
  5. Abstract:
  6. ATQ function prototypes and externs
  7. Author:
  8. Murali R. Krishnan ( MuraliK ) 1-June-1995
  9. Environment:
  10. User Mode -- Win32
  11. Project:
  12. Internet Services Common DLL
  13. Revision History:
  14. --*/
  15. #ifndef _ATQPROCS_H_
  16. #define _ATQPROCS_H_
  17. /************************************************************
  18. * Data
  19. * for detailed doc on global data, please see atqmain.cxx
  20. ************************************************************/
  21. // ------------------------------
  22. // Configuration for ATQ package
  23. // ------------------------------
  24. extern DWORD g_cConcurrency;
  25. extern BOOL g_fUseAcceptEx; // Use AcceptEx if available
  26. extern BOOL g_fUseDriver; // Use NTS kernel driver
  27. extern DWORD g_cbMinKbSec;
  28. extern DWORD g_msThreadTimeout;
  29. extern LONG g_cMaxThreads;
  30. extern LONG g_cMaxThreadLimit;
  31. extern DWORD g_dwNumContextLists;
  32. extern ATQ_THREAD_EXIT_CALLBACK g_pfnExitThreadCallback;
  33. extern BOOL g_fUseFakeCompletionPort;
  34. extern BOOL g_fEnableDebugThreads;
  35. extern BOOL g_fCreateDebugThread;
  36. extern DWORD g_cForceTimeout;
  37. extern BOOL g_fDisableBacklogMonitor;
  38. // ------------------------------
  39. // Current State Information
  40. // ------------------------------
  41. extern DWORD g_cListenBacklog;
  42. extern LONG g_cThreads;
  43. extern LONG g_cAvailableThreads;
  44. extern HANDLE g_hCompPort;
  45. extern HANDLE g_hShutdownEvent;
  46. extern BOOL g_fShutdown;
  47. //
  48. // Win95 specific
  49. //
  50. extern DWORD g_AtqWaitingContextsCount;
  51. // ------------------------------
  52. // Various State/Object Lists
  53. // ------------------------------
  54. extern DWORD AtqGlobalContextCount;
  55. extern DWORD g_AtqCurrentTick;
  56. extern DWORD g_cbXmitBufferSize;
  57. extern ATQ_CONTEXT_LISTHEAD AtqActiveContextList[];
  58. extern LIST_ENTRY AtqEndpointList;
  59. extern CRITICAL_SECTION AtqEndpointLock;
  60. extern PALLOC_CACHE_HANDLER g_pachAtqContexts;
  61. //
  62. // DLL handles
  63. //
  64. extern HINSTANCE g_hMSWsock;
  65. extern HINSTANCE g_hNtdll;
  66. //
  67. // Ensure that initialization/termination don't happen at the same time
  68. //
  69. extern CRITICAL_SECTION g_csInitTermLock;
  70. /************************************************************
  71. * Functions
  72. ************************************************************/
  73. VOID AtqValidateProductType( VOID );
  74. //
  75. // ATQ Context alloc/free functions
  76. //
  77. BOOL
  78. I_AtqCheckThreadStatus(
  79. IN PVOID Context = NULL
  80. );
  81. // for adding initial listen socket to the port
  82. // for adding non-AcceptEx() AtqContext()
  83. BOOL
  84. I_AtqAddAsyncHandle(
  85. IN OUT PATQ_CONT * ppatqContext,
  86. IN PATQ_ENDPOINT pEndpoint,
  87. PVOID ClientContext,
  88. ATQ_COMPLETION pfnCompletion,
  89. DWORD TimeOut,
  90. HANDLE hAsyncIO
  91. );
  92. // for adding an AcceptEx atq context to the atq processing
  93. BOOL
  94. I_AtqAddAsyncHandleEx(
  95. PATQ_CONT * ppatqContext,
  96. PATQ_ENDPOINT pEndpoint,
  97. PATQ_CONT pReuseableAtq
  98. );
  99. BOOL
  100. I_AtqPrepareAcceptExSockets(
  101. IN PATQ_ENDPOINT pEndpoint,
  102. IN DWORD nAcceptExSockets
  103. );
  104. BOOL
  105. I_AtqAddAcceptExSocket(
  106. IN PATQ_ENDPOINT pEndpoint,
  107. IN PATQ_CONT patqContext
  108. );
  109. BOOL
  110. I_AtqAddListenEndpointToPort(
  111. IN OUT PATQ_CONT * ppatqContext,
  112. IN PATQ_ENDPOINT pEndpoint
  113. );
  114. VOID
  115. I_AtqProcessPendingListens(
  116. IN PATQ_CONTEXT_LISTHEAD pContextList,
  117. IN PATQ_ENDPOINT pEndpoint,
  118. OUT PDWORD pcForced
  119. );
  120. BOOL
  121. I_AtqStartTimeoutProcessing(
  122. IN PVOID Context
  123. );
  124. BOOL
  125. I_AtqStopTimeoutProcessing(
  126. VOID
  127. );
  128. BOOL
  129. SIOTransmitFile(
  130. IN PATQ_CONT pContext,
  131. IN HANDLE hFile,
  132. IN DWORD dwBytesInFile,
  133. IN LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers
  134. );
  135. BOOL
  136. I_AtqInitializeNtEntryPoints(
  137. VOID
  138. );
  139. BOOL
  140. I_AtqSpudInitialize(
  141. VOID
  142. );
  143. BOOL
  144. I_AtqSpudTerminate(
  145. VOID
  146. );
  147. BOOL
  148. I_AtqTransmitFileAndRecv(
  149. IN PATQ_CONTEXT patqContext, // pointer to ATQ context
  150. IN HANDLE hFile, // handle of file to read
  151. IN DWORD dwBytesInFile, // Bytes to transmit
  152. IN LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers, // transmit buffer structure
  153. IN DWORD dwTFFlags, // TF Flags
  154. IN LPWSABUF pwsaBuffers, // Buffers for recv
  155. IN DWORD dwBufferCount
  156. );
  157. BOOL
  158. I_AtqSendAndRecv(
  159. IN PATQ_CONTEXT patqContext, // pointer to ATQ context
  160. IN LPWSABUF pwsaSendBuffers, // buffers for send
  161. IN DWORD dwSendBufferCount, // count of buffers for send
  162. IN LPWSABUF pwsaRecvBuffers, // Buffers for recv
  163. IN DWORD dwRecvBufferCount // count of buffers for recv
  164. );
  165. VOID
  166. AtqpReuseOrFreeContext(
  167. IN PATQ_CONT pContext,
  168. IN BOOL fReuseContext
  169. );
  170. VOID
  171. AtqpProcessContext( IN PATQ_CONT pAtqContext,
  172. IN DWORD cbWritten,
  173. IN LPOVERLAPPED lpo,
  174. IN BOOL fRet);
  175. //
  176. // win 95
  177. //
  178. BOOL
  179. SIOGetQueuedCompletionStatus(
  180. IN HANDLE hExistingPort,
  181. OUT LPDWORD lpdwBytesTransferred,
  182. OUT PULONG_PTR lpdwCompletionKey,
  183. OUT LPOVERLAPPED *lplpOverlapped,
  184. IN DWORD msThreadTimeout
  185. );
  186. BOOL
  187. SIOStartAsyncOperation(
  188. IN HANDLE hExistingPort,
  189. IN PATQ_CONTEXT pAtqContext
  190. );
  191. BOOL
  192. SIODestroyCompletionPort(
  193. IN HANDLE hExistingPort
  194. );
  195. HANDLE
  196. SIOCreateCompletionPort(
  197. IN HANDLE hAsyncIO,
  198. IN HANDLE hExistingPort,
  199. IN ULONG_PTR dwCompletionKey,
  200. IN DWORD dwConcurrentThreads
  201. );
  202. BOOL
  203. SIOPostCompletionStatus(
  204. IN HANDLE hExistingPort,
  205. IN DWORD dwBytesTransferred,
  206. IN ULONG_PTR dwCompletionKey,
  207. IN LPOVERLAPPED lpOverlapped
  208. );
  209. BOOL
  210. SIOWSARecv(
  211. IN PATQ_CONT patqContext,
  212. IN LPWSABUF pwsaBuffers,
  213. IN DWORD dwBufferCount,
  214. IN OVERLAPPED * lpo OPTIONAL
  215. );
  216. BOOL
  217. SIOWSASend(
  218. IN PATQ_CONT patqContext,
  219. IN LPWSABUF pwsaBuffers,
  220. IN DWORD dwBufferCount,
  221. IN OVERLAPPED * lpo OPTIONAL
  222. );
  223. BOOL
  224. SIOTransmitFile(
  225. IN PATQ_CONT pContext,
  226. IN HANDLE hFile,
  227. IN DWORD dwBytesInFile,
  228. IN LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers
  229. );
  230. typedef
  231. HANDLE
  232. (*PFN_CREATE_COMPLETION_PORT) (
  233. IN HANDLE hFile,
  234. IN HANDLE hPort,
  235. IN ULONG_PTR dwKey,
  236. IN DWORD nThreads
  237. );
  238. typedef
  239. BOOL
  240. (*PFN_CLOSE_COMPLETION_PORT) (
  241. IN HANDLE hFile
  242. );
  243. typedef
  244. BOOL
  245. (WINAPI *PFN_GET_QUEUED_COMPLETION_STATUS)(
  246. HANDLE CompletionPort,
  247. LPDWORD lpNumberOfBytesTransferred,
  248. PULONG_PTR lpCompletionKey,
  249. LPOVERLAPPED *lpOverlapped,
  250. DWORD dwMilliseconds
  251. );
  252. typedef
  253. BOOL
  254. (WINAPI *PFN_POST_COMPLETION_STATUS)(
  255. HANDLE CompletionPort,
  256. DWORD dwNumberOfBytesTransferred,
  257. ULONG_PTR dwCompletionKey,
  258. LPOVERLAPPED lpOverlapped
  259. );
  260. typedef
  261. BOOL
  262. (*PFN_ACCEPTEX) (
  263. IN SOCKET sListenSocket,
  264. IN SOCKET sAcceptSocket,
  265. IN PVOID lpOutputBuffer,
  266. IN DWORD dwReceiveDataLength,
  267. IN DWORD dwLocalAddressLength,
  268. IN DWORD dwRemoteAddressLength,
  269. OUT LPDWORD lpdwBytesReceived,
  270. IN LPOVERLAPPED lpOverlapped
  271. );
  272. typedef
  273. VOID
  274. (*PFN_GETACCEPTEXSOCKADDRS) (
  275. IN PVOID lpOutputBuffer,
  276. IN DWORD dwReceiveDataLength,
  277. IN DWORD dwLocalAddressLength,
  278. IN DWORD dwRemoteAddressLength,
  279. OUT struct sockaddr **LocalSockaddr,
  280. OUT LPINT LocalSockaddrLength,
  281. OUT struct sockaddr **RemoteSockaddr,
  282. OUT LPINT RemoteSockaddrLength
  283. );
  284. typedef
  285. BOOL
  286. (*PFN_TRANSMITFILE) (
  287. IN SOCKET hSocket,
  288. IN HANDLE hFile,
  289. IN DWORD nBytesWrite,
  290. IN DWORD nBytesPerSend,
  291. IN LPOVERLAPPED lpo,
  292. IN LPTRANSMIT_FILE_BUFFERS lpTransmitBuffer,
  293. IN DWORD dwReserved
  294. );
  295. typedef
  296. BOOL
  297. (WINAPI *PFN_READ_DIR_CHANGES_W)(
  298. HANDLE hDirectory,
  299. LPVOID lpBuffer,
  300. DWORD nBufferLength,
  301. BOOL bWatchSubtree,
  302. DWORD dwNotifyFilter,
  303. LPDWORD lpBytesReturned,
  304. LPOVERLAPPED lpOverlapped,
  305. LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
  306. );
  307. extern PFN_ACCEPTEX g_pfnAcceptEx;
  308. extern PFN_GETACCEPTEXSOCKADDRS g_pfnGetAcceptExSockaddrs;
  309. extern PFN_TRANSMITFILE g_pfnTransmitFile;
  310. extern PFN_READ_DIR_CHANGES_W g_pfnReadDirChangesW;
  311. extern PFN_GET_QUEUED_COMPLETION_STATUS g_pfnGetQueuedCompletionStatus;
  312. extern PFN_CREATE_COMPLETION_PORT g_pfnCreateCompletionPort;
  313. extern PFN_CLOSE_COMPLETION_PORT g_pfnCloseCompletionPort;
  314. extern PFN_POST_COMPLETION_STATUS g_pfnPostCompletionStatus;
  315. //
  316. // ntdll
  317. //
  318. typedef
  319. VOID
  320. (NTAPI *PFN_RTL_INIT_UNICODE_STRING)(
  321. PUNICODE_STRING DestinationString,
  322. PCWSTR SourceString
  323. );
  324. typedef
  325. ULONG
  326. (NTAPI *PFN_RTL_NTSTATUS_TO_DOSERR)(
  327. NTSTATUS Status
  328. );
  329. typedef
  330. VOID
  331. (NTAPI *PFN_RTL_INIT_ANSI_STRING)(
  332. PANSI_STRING DestinationString,
  333. PCSZ SourceString
  334. );
  335. typedef
  336. NTSTATUS
  337. (NTAPI *PFN_RTL_ANSI_STRING_TO_UNICODE_STRING)(
  338. PUNICODE_STRING DestinationString,
  339. PANSI_STRING SourceString,
  340. BOOLEAN AllocateDestinationString
  341. );
  342. typedef
  343. BOOLEAN
  344. (NTAPI *PFN_RTL_FREE_HEAP)(
  345. IN PVOID HeapHandle,
  346. IN ULONG Flags,
  347. IN PVOID BaseAddress
  348. );
  349. typedef
  350. BOOLEAN
  351. (NTAPI *PFN_RTL_DOS_PATHNAME_TO_NT_PATHNAME)(
  352. PCWSTR DosFileName,
  353. PUNICODE_STRING NtFileName,
  354. PWSTR *FilePart OPTIONAL,
  355. PRTL_RELATIVE_NAME RelativeName OPTIONAL
  356. );
  357. typedef
  358. NTSTATUS
  359. (NTAPI *PFN_NT_LOAD_DRIVER)(
  360. PUNICODE_STRING DriverName
  361. );
  362. extern PFN_RTL_INIT_UNICODE_STRING g_pfnRtlInitUnicodeString;
  363. extern PFN_RTL_NTSTATUS_TO_DOSERR g_pfnRtlNtStatusToDosError;
  364. extern PFN_NT_LOAD_DRIVER g_pfnNtLoadDriver;
  365. extern PFN_RTL_INIT_ANSI_STRING g_pfnRtlInitAnsiString;
  366. extern PFN_RTL_ANSI_STRING_TO_UNICODE_STRING g_pfnRtlAnsiStringToUnicodeString;
  367. extern PFN_RTL_DOS_PATHNAME_TO_NT_PATHNAME g_pfnRtlDosPathNameToNtPathName_U;
  368. extern PFN_RTL_FREE_HEAP g_pfnRtlFreeHeap;
  369. //
  370. // inlined functions
  371. //
  372. inline BOOL
  373. I_AddAtqContextToPort(IN PATQ_CONT pAtqContext)
  374. {
  375. ATQ_ASSERT( g_hCompPort );
  376. return (g_pfnCreateCompletionPort(
  377. pAtqContext->hAsyncIO,
  378. g_hCompPort,
  379. (ULONG_PTR)pAtqContext,
  380. g_cConcurrency
  381. ) != NULL
  382. );
  383. } // I_AddContextToPort()
  384. inline DWORD CanonTimeout( DWORD Timeout)
  385. // Convert the timeout into normalized ATQ timeout value
  386. {
  387. return ((Timeout == INFINITE) ? ATQ_INFINITE :
  388. ((Timeout + ATQ_TIMEOUT_INTERVAL - 1)/ATQ_TIMEOUT_INTERVAL + 1)
  389. );
  390. } // CanonTimeout()
  391. inline DWORD UndoCanonTimeout( DWORD Timeout)
  392. // Convert the timeout from normalized ATQ timeout into values in seconds
  393. {
  394. return ( ((Timeout & ATQ_INFINITE) != 0) ? INFINITE :
  395. ((Timeout - 1) * ATQ_TIMEOUT_INTERVAL)
  396. );
  397. } // UndoCanonTimeout()
  398. #endif // _ATQPROCS_H_