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.

332 lines
8.3 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_fEnableDebugThreads;
  34. extern BOOL g_fCreateDebugThread;
  35. extern DWORD g_cForceTimeout;
  36. extern BOOL g_fDisableBacklogMonitor;
  37. // ------------------------------
  38. // Current State Information
  39. // ------------------------------
  40. extern DWORD g_cListenBacklog;
  41. extern LONG g_cThreads;
  42. extern LONG g_cAvailableThreads;
  43. extern HANDLE g_hCompPort;
  44. extern HANDLE g_hShutdownEvent;
  45. extern BOOL g_fShutdown;
  46. // ------------------------------
  47. // Various State/Object Lists
  48. // ------------------------------
  49. extern DWORD AtqGlobalContextCount;
  50. extern DWORD g_AtqCurrentTick;
  51. extern ATQ_CONTEXT_LISTHEAD AtqActiveContextList[];
  52. extern LIST_ENTRY AtqEndpointList;
  53. extern CRITICAL_SECTION AtqEndpointLock;
  54. extern PALLOC_CACHE_HANDLER g_pachAtqContexts;
  55. //
  56. // DLL handles
  57. //
  58. extern HINSTANCE g_hMSWsock;
  59. //
  60. // Ensure that initialization/termination don't happen at the same time
  61. //
  62. extern CRITICAL_SECTION g_csInitTermLock;
  63. /************************************************************
  64. * Functions
  65. ************************************************************/
  66. VOID AtqValidateProductType( VOID );
  67. //
  68. // ATQ Context alloc/free functions
  69. //
  70. BOOL
  71. I_AtqCheckThreadStatus(
  72. IN PVOID Context = NULL
  73. );
  74. // for adding initial listen socket to the port
  75. // for adding non-AcceptEx() AtqContext()
  76. BOOL
  77. I_AtqAddAsyncHandle(
  78. IN OUT PATQ_CONT * ppatqContext,
  79. IN PATQ_ENDPOINT pEndpoint,
  80. PVOID ClientContext,
  81. ATQ_COMPLETION pfnCompletion,
  82. DWORD TimeOut,
  83. HANDLE hAsyncIO
  84. );
  85. // for adding an AcceptEx atq context to the atq processing
  86. BOOL
  87. I_AtqAddAsyncHandleEx(
  88. PATQ_CONT * ppatqContext,
  89. PATQ_ENDPOINT pEndpoint,
  90. PATQ_CONT pReuseableAtq
  91. );
  92. BOOL
  93. I_AtqPrepareAcceptExSockets(
  94. IN PATQ_ENDPOINT pEndpoint,
  95. IN DWORD nAcceptExSockets
  96. );
  97. BOOL
  98. I_AtqAddAcceptExSocket(
  99. IN PATQ_ENDPOINT pEndpoint,
  100. IN PATQ_CONT patqContext
  101. );
  102. BOOL
  103. I_AtqAddListenEndpointToPort(
  104. IN OUT PATQ_CONT * ppatqContext,
  105. IN PATQ_ENDPOINT pEndpoint
  106. );
  107. VOID
  108. I_AtqProcessPendingListens(
  109. IN PATQ_CONTEXT_LISTHEAD pContextList,
  110. IN PATQ_ENDPOINT pEndpoint,
  111. OUT PDWORD pcForced
  112. );
  113. BOOL
  114. I_AtqStartTimeoutProcessing(
  115. IN PVOID Context
  116. );
  117. BOOL
  118. I_AtqStopTimeoutProcessing(
  119. VOID
  120. );
  121. BOOL
  122. I_AtqInitializeNtEntryPoints(
  123. VOID
  124. );
  125. BOOL
  126. I_AtqTransmitFileAndRecv(
  127. IN PATQ_CONTEXT patqContext, // pointer to ATQ context
  128. IN HANDLE hFile, // handle of file to read
  129. IN DWORD dwBytesInFile, // Bytes to transmit
  130. IN LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers, // transmit buffer structure
  131. IN DWORD dwTFFlags, // TF Flags
  132. IN LPWSABUF pwsaBuffers, // Buffers for recv
  133. IN DWORD dwBufferCount
  134. );
  135. BOOL
  136. I_AtqSendAndRecv(
  137. IN PATQ_CONTEXT patqContext, // pointer to ATQ context
  138. IN LPWSABUF pwsaSendBuffers, // buffers for send
  139. IN DWORD dwSendBufferCount, // count of buffers for send
  140. IN LPWSABUF pwsaRecvBuffers, // Buffers for recv
  141. IN DWORD dwRecvBufferCount // count of buffers for recv
  142. );
  143. VOID
  144. AtqpReuseOrFreeContext(
  145. IN PATQ_CONT pContext,
  146. IN BOOL fReuseContext
  147. );
  148. VOID
  149. AtqpProcessContext( IN PATQ_CONT pAtqContext,
  150. IN DWORD cbWritten,
  151. IN LPOVERLAPPED lpo,
  152. IN BOOL fRet);
  153. typedef
  154. HANDLE
  155. (*PFN_CREATE_COMPLETION_PORT) (
  156. IN HANDLE hFile,
  157. IN HANDLE hPort,
  158. IN ULONG_PTR dwKey,
  159. IN DWORD nThreads
  160. );
  161. typedef
  162. BOOL
  163. (*PFN_CLOSE_COMPLETION_PORT) (
  164. IN HANDLE hFile
  165. );
  166. typedef
  167. BOOL
  168. (WINAPI *PFN_GET_QUEUED_COMPLETION_STATUS)(
  169. HANDLE CompletionPort,
  170. LPDWORD lpNumberOfBytesTransferred,
  171. PULONG_PTR lpCompletionKey,
  172. LPOVERLAPPED *lpOverlapped,
  173. DWORD dwMilliseconds
  174. );
  175. typedef
  176. BOOL
  177. (WINAPI *PFN_POST_COMPLETION_STATUS)(
  178. HANDLE CompletionPort,
  179. DWORD dwNumberOfBytesTransferred,
  180. ULONG_PTR dwCompletionKey,
  181. LPOVERLAPPED lpOverlapped
  182. );
  183. typedef
  184. BOOL
  185. (*PFN_ACCEPTEX) (
  186. IN SOCKET sListenSocket,
  187. IN SOCKET sAcceptSocket,
  188. IN PVOID lpOutputBuffer,
  189. IN DWORD dwReceiveDataLength,
  190. IN DWORD dwLocalAddressLength,
  191. IN DWORD dwRemoteAddressLength,
  192. OUT LPDWORD lpdwBytesReceived,
  193. IN LPOVERLAPPED lpOverlapped
  194. );
  195. typedef
  196. VOID
  197. (*PFN_GETACCEPTEXSOCKADDRS) (
  198. IN PVOID lpOutputBuffer,
  199. IN DWORD dwReceiveDataLength,
  200. IN DWORD dwLocalAddressLength,
  201. IN DWORD dwRemoteAddressLength,
  202. OUT struct sockaddr **LocalSockaddr,
  203. OUT LPINT LocalSockaddrLength,
  204. OUT struct sockaddr **RemoteSockaddr,
  205. OUT LPINT RemoteSockaddrLength
  206. );
  207. typedef
  208. BOOL
  209. (*PFN_TRANSMITFILE) (
  210. IN SOCKET hSocket,
  211. IN HANDLE hFile,
  212. IN DWORD nBytesWrite,
  213. IN DWORD nBytesPerSend,
  214. IN LPOVERLAPPED lpo,
  215. IN LPTRANSMIT_FILE_BUFFERS lpTransmitBuffer,
  216. IN DWORD dwReserved
  217. );
  218. typedef
  219. BOOL
  220. (WINAPI *PFN_READ_DIR_CHANGES_W)(
  221. HANDLE hDirectory,
  222. LPVOID lpBuffer,
  223. DWORD nBufferLength,
  224. BOOL bWatchSubtree,
  225. DWORD dwNotifyFilter,
  226. LPDWORD lpBytesReturned,
  227. LPOVERLAPPED lpOverlapped,
  228. LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
  229. );
  230. extern PFN_ACCEPTEX g_pfnAcceptEx;
  231. extern PFN_GETACCEPTEXSOCKADDRS g_pfnGetAcceptExSockaddrs;
  232. extern PFN_TRANSMITFILE g_pfnTransmitFile;
  233. extern PFN_READ_DIR_CHANGES_W g_pfnReadDirChangesW;
  234. extern PFN_GET_QUEUED_COMPLETION_STATUS g_pfnGetQueuedCompletionStatus;
  235. extern PFN_CREATE_COMPLETION_PORT g_pfnCreateCompletionPort;
  236. extern PFN_CLOSE_COMPLETION_PORT g_pfnCloseCompletionPort;
  237. extern PFN_POST_COMPLETION_STATUS g_pfnPostCompletionStatus;
  238. //
  239. // inlined functions
  240. //
  241. inline BOOL
  242. I_AddAtqContextToPort(IN PATQ_CONT pAtqContext)
  243. {
  244. ATQ_ASSERT( g_hCompPort );
  245. return (g_pfnCreateCompletionPort(
  246. pAtqContext->hAsyncIO,
  247. g_hCompPort,
  248. (ULONG_PTR)pAtqContext,
  249. g_cConcurrency
  250. ) != NULL
  251. );
  252. } // I_AddContextToPort()
  253. inline DWORD CanonTimeout( DWORD Timeout)
  254. // Convert the timeout into normalized ATQ timeout value
  255. {
  256. return ((Timeout == INFINITE) ? ATQ_INFINITE :
  257. ((Timeout + ATQ_TIMEOUT_INTERVAL - 1)/ATQ_TIMEOUT_INTERVAL + 1)
  258. );
  259. } // CanonTimeout()
  260. inline DWORD UndoCanonTimeout( DWORD Timeout)
  261. // Convert the timeout from normalized ATQ timeout into values in seconds
  262. {
  263. return ( ((Timeout & ATQ_INFINITE) != 0) ? INFINITE :
  264. ((Timeout - 1) * ATQ_TIMEOUT_INTERVAL)
  265. );
  266. } // UndoCanonTimeout()
  267. #endif // _ATQPROCS_H_