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.

303 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. buffer.hxx
  5. Abstract:
  6. Contains types, manifests, prototypes for double buffering object
  7. (in buffer.cxx)
  8. Author:
  9. Arthur L Bierer (arthurbi) 20-March-1996
  10. Revision History:
  11. 20-March-1996 arthurbi
  12. Created
  13. --*/
  14. #ifndef BUFFER_H_
  15. #define BUFFER_H_
  16. //
  17. // DBLBUFFER Class
  18. //
  19. #define DBLBUFFER_DEFAULT_SIZE 1500
  20. #define DBLBUFFER_MAX_SIZE (32*1024)
  21. class DBLBUFFER {
  22. private:
  23. //
  24. // _lpBuffer - pointer to allocated buffer.
  25. //
  26. LPBYTE _lpBuffer;
  27. //
  28. // _dwBufferLength - current allocated size of the buffer
  29. //
  30. DWORD _dwBufferLength;
  31. //
  32. // _lpBufferIn - pointer where Input Buffer starts
  33. //
  34. LPBYTE _lpBufferIn;
  35. //
  36. // _dwBufferIn - size of input buffer in bytes.
  37. //
  38. DWORD _dwBufferIn;
  39. //
  40. // _lpBufferOut - pointer to where output buffer starts
  41. //
  42. LPBYTE _lpBufferOut;
  43. //
  44. // _dwBufferOut - size of output buffer.
  45. //
  46. DWORD _dwBufferOut;
  47. //
  48. // _dwInitDefaultBufferSize - default initial size of main buffer.
  49. //
  50. DWORD _dwInitDefaultBufferSize;
  51. //
  52. // Internal Varibles -----------------------------
  53. //
  54. //
  55. // _lpEndOfBuffer - points to end of the buffer.
  56. //
  57. LPBYTE _lpEndOfBuffer;
  58. //
  59. // fDblBufferMode - TRUE if we maintain an input buffer seperate from an output buffer
  60. // otherwise the input/output is considered the same (ie input buffer is not used)
  61. //
  62. BOOL _fDblBufferMode;
  63. VOID
  64. UpdateVars() {
  65. INET_ASSERT(_lpBuffer);
  66. _lpEndOfBuffer = _lpBuffer + _dwBufferLength;
  67. //
  68. // Dock Pointers at end of buffer for sanity checking later on
  69. //
  70. if ( _dwBufferOut == 0 )
  71. _lpBufferOut = _lpEndOfBuffer;
  72. if ( _dwBufferIn == 0 )
  73. _lpBufferIn = _lpEndOfBuffer;
  74. }
  75. public:
  76. DBLBUFFER(
  77. DWORD dwInitBufferSize) {
  78. _dwInitDefaultBufferSize = dwInitBufferSize;
  79. _dwBufferOut = 0;
  80. _dwBufferIn = 0;
  81. _lpBufferOut = NULL;
  82. _lpBufferIn = NULL;
  83. _lpBuffer = NULL;
  84. _dwBufferLength = 0;
  85. _fDblBufferMode = FALSE;
  86. }
  87. DBLBUFFER(
  88. VOID) {
  89. _dwInitDefaultBufferSize = DBLBUFFER_DEFAULT_SIZE;
  90. _dwBufferOut = 0;
  91. _dwBufferIn = 0;
  92. _lpBufferOut = NULL;
  93. _lpBufferIn = NULL;
  94. _lpBuffer = NULL;
  95. _dwBufferLength = 0;
  96. _fDblBufferMode = FALSE;
  97. }
  98. ~DBLBUFFER() {
  99. if ( _lpBuffer )
  100. {
  101. FREE_MEMORY(_lpBuffer);
  102. }
  103. }
  104. LPBYTE
  105. GetInputBufferPointer(
  106. VOID
  107. ) {
  108. DEBUG_ENTER((DBG_INET,
  109. Pointer,
  110. "DBLBUFFER::GetInputBufferPointer",
  111. NULL
  112. ));
  113. if ( _fDblBufferMode )
  114. {
  115. DEBUG_LEAVE((( _lpBufferIn == _lpEndOfBuffer ) ? _lpBuffer : _lpBufferIn));
  116. return ( _lpBufferIn == _lpEndOfBuffer ) ? _lpBuffer : _lpBufferIn;
  117. }
  118. else
  119. {
  120. DEBUG_LEAVE((( _lpBufferOut == _lpEndOfBuffer ) ? _lpBuffer : _lpBufferOut));
  121. return ( _lpBufferOut == _lpEndOfBuffer ) ? _lpBuffer : _lpBufferOut;
  122. }
  123. }
  124. DWORD
  125. GetInputBufferSize(
  126. VOID
  127. ) {
  128. DEBUG_ENTER((DBG_INET,
  129. Int,
  130. "DBLBUFFER::GetInputBufferSize",
  131. NULL
  132. ));
  133. if ( _fDblBufferMode )
  134. {
  135. DEBUG_LEAVE(_dwBufferIn);
  136. return _dwBufferIn;
  137. }
  138. else
  139. {
  140. DEBUG_LEAVE(_dwBufferOut);
  141. return _dwBufferOut;
  142. }
  143. }
  144. VOID
  145. SetInputBufferSize(
  146. IN DWORD dwNewInputBufferSize
  147. ) {
  148. DEBUG_ENTER((DBG_INET,
  149. None,
  150. "DBLBUFFER::SetInputBufferSize",
  151. "%u",
  152. dwNewInputBufferSize
  153. ));
  154. if ( _fDblBufferMode )
  155. {
  156. _dwBufferIn = dwNewInputBufferSize;
  157. }
  158. else
  159. {
  160. _dwBufferOut = dwNewInputBufferSize;
  161. }
  162. DEBUG_LEAVE(0);
  163. }
  164. DWORD
  165. GetOutputBufferSize(
  166. VOID
  167. ) {
  168. DEBUG_ENTER((DBG_INET,
  169. Int,
  170. "DBLBUFFER::GetOutputBufferSize",
  171. NULL
  172. ));
  173. DEBUG_LEAVE(_dwBufferOut);
  174. return _dwBufferOut;
  175. }
  176. BOOL
  177. InitBuffer(
  178. BOOL fDblBufferMode
  179. );
  180. DWORD
  181. GetInputBufferRemaining(
  182. VOID
  183. );
  184. BOOL
  185. CopyOut(
  186. OUT LPBYTE lpBuffer,
  187. IN OUT LPDWORD lpdwBufferRemaining,
  188. IN OUT LPDWORD lpdwBytesReceived,
  189. IN OUT LPDWORD lpdwBytesRead
  190. );
  191. BOOL
  192. CopyIn(
  193. IN LPBYTE lpBuffer,
  194. IN DWORD dwBufferSize
  195. );
  196. BOOL
  197. CompressInputBufferUsage(
  198. VOID
  199. );
  200. BOOL
  201. ConcatenateOutputBufferUsage(
  202. IN LPBYTE lpSecondOutputBuffer,
  203. IN DWORD dwSecondOutputBufferSize
  204. );
  205. BOOL
  206. ResizeBufferIfNeeded(
  207. IN DWORD dwAddlBufferNeeded
  208. );
  209. BOOL
  210. SetOutputInputBuffer(
  211. IN LPBYTE lpNewOutputBuffer,
  212. IN DWORD dwNewOutputBufferSize,
  213. IN LPBYTE lpNewInputBuffer,
  214. IN DWORD dwNewInputBufferSize,
  215. IN BOOL fConcatenatePreviousOutput
  216. );
  217. };
  218. #endif