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.

211 lines
6.2 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name :
  4. asyncio.hxx
  5. Abstract:
  6. This module declares a class for handling Asynchronous IO using
  7. ATQs and overlapped IO structures
  8. Author:
  9. Murali R. Krishnan ( MuraliK ) 27-March-1995
  10. Environment:
  11. User Mode -- Win32
  12. Project:
  13. Internet Services DLL
  14. Revision History:
  15. --*/
  16. # ifndef _ASYNCIO_HXX_
  17. # define _ASYNCIO_HXX_
  18. /************************************************************
  19. * Include Headers
  20. ************************************************************/
  21. //
  22. // Include NT/Windows headers
  23. //
  24. # include "atq.h"
  25. # define DEFAULT_CONNECTION_IO_TIMEOUT ( 60) // 1 minutes
  26. /************************************************************
  27. * Type Definitions
  28. ************************************************************/
  29. class ASYNC_IO_CONNECTION;
  30. typedef ASYNC_IO_CONNECTION * LPASYNC_IO_CONNECTION;
  31. extern VOID
  32. ProcessAtqCompletion(IN LPVOID pContext,
  33. IN DWORD cbIo,
  34. IN DWORD dwCompletionStatus,
  35. IN OVERLAPPED * lpo);
  36. /*++
  37. PFN_ASYNC_IO_COMPLETION:
  38. Call back function to be called at completion of the IO using
  39. ASYNC_IO_CONNECTION object.
  40. Parameters:
  41. pContext pointer to Context information for call back.
  42. cbIo count of bytes involved in IO
  43. dwCompletionStatus DWORD containing the Error code ( if any errors)
  44. for last IO operation.
  45. pAic pointer to the Asynchronous IO object involved in
  46. processing last request.
  47. fTimedOut indicates if the request was timed out.
  48. --*/
  49. typedef VOID ( * PFN_ASYNC_IO_COMPLETION)(
  50. IN LPVOID pContext,
  51. IN DWORD cbIo,
  52. IN DWORD dwCompletionStatus,
  53. IN LPASYNC_IO_CONNECTION pAic,
  54. IN BOOL fTimedOut
  55. );
  56. /*++
  57. class ASYNC_IO_CONNECTION:
  58. This class maintains state of an asynchronous IO operation.
  59. It supports async Read, Write and TransmitFile operations
  60. for the user of its objects.
  61. It also maintains state regarding timeout, user context
  62. --*/
  63. class ASYNC_IO_CONNECTION {
  64. public:
  65. enum ASYNC_IO_OPERATION {
  66. AioNone,
  67. AioRead,
  68. AioWrite,
  69. AioTransmitFile,
  70. AioError
  71. };
  72. ASYNC_IO_CONNECTION( IN PFN_ASYNC_IO_COMPLETION pfnCompletion,
  73. IN SOCKET sClient = INVALID_SOCKET);
  74. virtual ~ASYNC_IO_CONNECTION( VOID);
  75. VOID SetAioContext(IN LPVOID pContext) { m_pAioContext = pContext; }
  76. SOCKET QuerySocket( VOID) const { return ( m_sClient); }
  77. HANDLE QueryFile( VOID) const { return (HANDLE) QuerySocket(); }
  78. LPVOID QueryAioContext( VOID) const { return ( m_pAioContext); }
  79. PFN_ASYNC_IO_COMPLETION QueryPfnAioCompletion( VOID) const
  80. { return ( m_pfnAioCompletion); }
  81. PATQ_CONTEXT QueryAtqContext(VOID) const { return ( m_pAtqContext); }
  82. DWORD QueryIoTimeout( VOID) const { return (m_sTimeout);}
  83. VOID SetIoTimeout(IN DWORD sTimeout) { m_sTimeout = sTimeout; }
  84. // This function should be called once per object for new socket.
  85. VOID SetAioInformation( IN LPVOID pContext, IN DWORD sTimeout)
  86. {
  87. m_pAioContext = pContext;
  88. m_sTimeout = sTimeout;
  89. }
  90. // returns the timetilltimeout value from atq or locally.
  91. DWORD ResumeIoOperation(VOID)
  92. {
  93. if ( m_pAtqContext != NULL) {
  94. // no valid 3rd parameter required for setting this info.
  95. // just to satisfy compiler send 0 as 3rd param
  96. return (DWORD)AtqContextSetInfo( m_pAtqContext, ATQ_INFO_RESUME_IO, 0);
  97. }
  98. return ( INFINITE); // No Outstanding IO; so send INFINITE.
  99. }
  100. BOOL SetNewSocket(IN SOCKET sNewSocket,
  101. IN PATQ_CONTEXT pAtqContext = NULL,
  102. IN PVOID EndpointObject = NULL);
  103. BOOL SetNewFile(IN HANDLE hNewFile);
  104. BOOL ReadFile(
  105. OUT LPVOID pvBuffer,
  106. IN DWORD cbSize,
  107. IN LONGLONG liOffset = 0);
  108. BOOL WriteFile(
  109. IN LPVOID pvBuffer,
  110. IN DWORD cbSize,
  111. IN LONGLONG liOffset = 0);
  112. BOOL TransmitFile(
  113. IN HANDLE hFile,
  114. IN LARGE_INTEGER & liSize,
  115. IN LONGLONG llOffset,
  116. IN LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers = NULL
  117. );
  118. BOOL TransmitFileTs(
  119. IN TS_OPEN_FILE_INFO * pOpenFile,
  120. IN LARGE_INTEGER & liSize,
  121. IN LONGLONG llOffset,
  122. IN BOOL fDisconnectSocket
  123. );
  124. BOOL StopIo( IN DWORD dwErrorCode = NO_ERROR);
  125. # if DBG
  126. VOID Print( VOID) const;
  127. # endif // DBG
  128. private:
  129. // data required for callback and establishing Atq connection.
  130. LPVOID m_pAioContext;
  131. PFN_ASYNC_IO_COMPLETION m_pfnAioCompletion;
  132. DWORD m_sTimeout; // timeout in seconds
  133. // data related to Async io.
  134. SOCKET m_sClient; // this can also be a file handle
  135. BOOL m_fFileIO; // indicates the m_sClient has a file handle
  136. PATQ_CONTEXT m_pAtqContext;
  137. PVOID m_endpointObject;
  138. BOOL AddToAtqHandles( VOID)
  139. {
  140. return ( AtqAddAsyncHandle( &m_pAtqContext,
  141. m_endpointObject,
  142. this,
  143. ProcessAtqCompletion,
  144. QueryIoTimeout(),
  145. (HANDLE)m_sClient)
  146. );
  147. } // AddToAtqHandles()
  148. }; // class ASYNC_IO_CONNECTION:
  149. # endif // _ASYNCIO_HXX_
  150. /************************ End of File ***********************/