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.

133 lines
2.8 KiB

  1. #ifndef _HEADERBUFFER_HXX_
  2. #define _HEADERBUFFER_HXX_
  3. #define BUFFER_MIN_SIZE 256
  4. // disable warning on 0 sized array
  5. #pragma warning( push )
  6. #pragma warning( disable : 4200 )
  7. struct BUFFER_LINK
  8. {
  9. BUFFER_LINK * _pNext;
  10. DWORD _cbSize;
  11. DWORD _cbOffset;
  12. CHAR _pchBuffer[ 0 ];
  13. };
  14. #pragma warning( pop )
  15. class IRTL_DLLEXP CHUNK_BUFFER
  16. {
  17. public:
  18. CHUNK_BUFFER()
  19. {
  20. Initialize();
  21. }
  22. ~CHUNK_BUFFER()
  23. {
  24. FreeAllAllocatedSpace();
  25. }
  26. VOID
  27. FreeAllAllocatedSpace(
  28. VOID
  29. )
  30. {
  31. BUFFER_LINK * pCursor = _pBufferHead->_pNext;
  32. BUFFER_LINK * pNext;
  33. while( pCursor != NULL )
  34. {
  35. //
  36. // always skip first block because it is not dynamically allocated
  37. //
  38. pNext = pCursor->_pNext;
  39. LocalFree( pCursor );
  40. pCursor = pNext;
  41. }
  42. Initialize();
  43. }
  44. HRESULT
  45. AllocateSpace(
  46. LPWSTR pszHeaderValue,
  47. DWORD cchHeaderValue,
  48. LPWSTR * ppszBuffer
  49. );
  50. HRESULT
  51. AllocateSpace(
  52. CHAR * pszHeaderValue,
  53. DWORD cchHeaderValue,
  54. CHAR * * ppszBuffer
  55. );
  56. HRESULT
  57. AllocateSpace(
  58. DWORD cbSize,
  59. PWSTR * ppvBuffer
  60. );
  61. HRESULT
  62. AllocateSpace(
  63. DWORD cbSize,
  64. PCHAR * ppvBuffer
  65. );
  66. HRESULT
  67. AllocateSpace(
  68. DWORD cbSize,
  69. PVOID * ppvBuffer
  70. );
  71. DWORD
  72. QueryHeapAllocCount(
  73. VOID
  74. )
  75. /*++
  76. Routine Description:
  77. return number of allocations for chunk buffer that couldn't be handled
  78. internally and had to go to heap
  79. Arguments:
  80. Return Value:
  81. DWORD
  82. --*/
  83. {
  84. return _dwHeapAllocCount;
  85. }
  86. private:
  87. HRESULT
  88. AddNewBlock(
  89. DWORD cbSize
  90. );
  91. VOID
  92. Initialize(
  93. VOID
  94. )
  95. {
  96. _dwHeapAllocCount = 0;
  97. _pBufferHead = (BUFFER_LINK*) _rgInlineBuffer;
  98. _pBufferHead->_pNext = NULL;
  99. _pBufferHead->_cbSize = sizeof( _rgInlineBuffer ) - sizeof( BUFFER_LINK );
  100. _pBufferHead->_cbOffset = 0;
  101. _pBufferCurrent = _pBufferHead;
  102. }
  103. BUFFER_LINK * _pBufferHead;
  104. BUFFER_LINK * _pBufferCurrent;
  105. BYTE _rgInlineBuffer[ BUFFER_MIN_SIZE ];
  106. DWORD _dwHeapAllocCount;
  107. };
  108. #endif