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.

123 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1991-92 Microsoft Corporation
  3. Module Name:
  4. PrefMax.c
  5. Abstract:
  6. This module contains NetpAdjustPreferedMaximum.
  7. Author:
  8. John Rogers (JohnRo) 24-Mar-1991
  9. Environment:
  10. Portable to any flat, 32-bit environment. (Uses Win32 typedefs.)
  11. Requires ANSI C extensions: slash-slash comments, long external names.
  12. Revision History:
  13. 24-Mar-91 JohnRo
  14. Created.
  15. 03-May-1991 JohnRo
  16. Added (quiet) debug output. Fixed massive bug (I was using % for
  17. division - it must have been a long day).
  18. 03-Apr-1992 JohnRo
  19. Handle preferred maximum of (DWORD)-1.
  20. Avoid NT-specific header files if we don't need them.
  21. 04-Apr-1992 JohnRo
  22. Use MAX_PREFERRED_LENGTH equate.
  23. --*/
  24. // These must be included first:
  25. #include <windef.h> // IN, DWORD, etc.
  26. #include <lmcons.h> // NET_API_STATUS.
  27. // These may be included in any order:
  28. #include <debuglib.h> // IF_DEBUG().
  29. #include <netdebug.h> // FORMAT_DWORD, NetpKdPrint(()).
  30. #include <netlib.h> // My prototype, NetpSetOptionalArg().
  31. VOID
  32. NetpAdjustPreferedMaximum (
  33. IN DWORD PreferedMaximum,
  34. IN DWORD EntrySize,
  35. IN DWORD Overhead,
  36. OUT LPDWORD BytesToAllocate OPTIONAL,
  37. OUT LPDWORD EntriesToAllocate OPTIONAL
  38. )
  39. /*++
  40. Routine Description:
  41. NetpAdjustPreferedMaximum analyzes the prefered maximum length and
  42. compares it with the size of an entry and the total overhead.
  43. Arguments:
  44. PreferedMaximum - the number of bytes "prefered" by the application for
  45. a given buffer.
  46. EntrySize - the number of bytes for each entry.
  47. Overhead - the number of bytes (if any) of overhead. For instance,
  48. some enum operations have a null at the end of the array returned.
  49. BytesToAllocate - optionally points to a DWORD which will be set on
  50. output to the number of bytes to allocate (consistent with the
  51. prefered maximum, entry size, and overhead).
  52. EntriesToAllocate - optionally points to a DWORD which will be set with
  53. the number of entries which BytesToAllocate can contain.
  54. Return Value:
  55. None.
  56. --*/
  57. {
  58. if ( (PreferedMaximum <= (EntrySize+Overhead)) ||
  59. (PreferedMaximum == MAX_PREFERRED_LENGTH) ) {
  60. NetpSetOptionalArg(BytesToAllocate, EntrySize+Overhead);
  61. NetpSetOptionalArg(EntriesToAllocate, 1);
  62. } else {
  63. DWORD EntryCount;
  64. EntryCount = (PreferedMaximum-Overhead) / EntrySize;
  65. NetpSetOptionalArg(
  66. BytesToAllocate,
  67. (EntryCount*EntrySize) + Overhead);
  68. NetpSetOptionalArg(EntriesToAllocate, EntryCount);
  69. }
  70. IF_DEBUG(PREFMAX) {
  71. NetpKdPrint(("NetpAdjustPreferedMaximum: "
  72. "pref max=" FORMAT_DWORD ", "
  73. "entry size=" FORMAT_DWORD ", "
  74. "overhead=" FORMAT_DWORD ".\n",
  75. PreferedMaximum, EntrySize, Overhead));
  76. if (BytesToAllocate != NULL) {
  77. NetpKdPrint(("NetpAdjustPreferedMaximum: bytes to allocate="
  78. FORMAT_DWORD ".\n", *BytesToAllocate));
  79. }
  80. if (EntriesToAllocate != NULL) {
  81. NetpKdPrint(("NetpAdjustPreferedMaximum: Entries to allocate="
  82. FORMAT_DWORD ".\n", *EntriesToAllocate));
  83. }
  84. }
  85. }