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.

158 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1998, Microsoft Corporation
  3. Module Name:
  4. buffer.h
  5. Abstract:
  6. This module contains declarations for buffer-management.
  7. All network I/O in this component occurs via completion packets.
  8. The buffer routines below are used to acquire and release the buffers
  9. used for sending and receiving data.
  10. In addition to holding the data transferred, the buffers contain fields
  11. to facilitate their use with completion ports. See below for details
  12. on the use of the fields.
  13. Author:
  14. Abolade Gbadegesin (aboladeg) 2-Mar-1998
  15. Revision History:
  16. --*/
  17. #ifndef _NATHLP_BUFFER_H_
  18. #define _NATHLP_BUFFER_H_
  19. #define NH_BUFFER_SIZE 576
  20. #define NH_MAX_BUFFER_QUEUE_LENGTH 32
  21. struct _NH_BUFFER;
  22. //
  23. // Typedef: PNH_COMPLETION_ROUTINE
  24. //
  25. typedef
  26. VOID
  27. (*PNH_COMPLETION_ROUTINE)(
  28. ULONG ErrorCode,
  29. ULONG BytesTransferred,
  30. struct _NH_BUFFER* Bufferp
  31. );
  32. //
  33. // Structure: NH_BUFFER
  34. //
  35. // This structure holds a buffer used for network I/O on a socket.
  36. //
  37. typedef enum _NH_BUFFER_TYPE {
  38. NhFixedLengthBufferType,
  39. NhVariableLengthBufferType
  40. } NH_BUFFER_TYPE;
  41. typedef struct _NH_BUFFER {
  42. union {
  43. LIST_ENTRY Link;
  44. NH_BUFFER_TYPE Type;
  45. };
  46. //
  47. // The socket associated with the buffer's most recent I/O request
  48. //
  49. SOCKET Socket;
  50. //
  51. // Completion routine and contexts for the buffer's most recent I/O request
  52. //
  53. PNH_COMPLETION_ROUTINE CompletionRoutine;
  54. PVOID Context;
  55. PVOID Context2;
  56. //
  57. // Passed as the system context area for any I/O using the buffer
  58. //
  59. OVERLAPPED Overlapped;
  60. //
  61. // Upon completion of a receive, the receive-flags and source-address
  62. // length for the message read
  63. //
  64. ULONG ReceiveFlags;
  65. ULONG AddressLength;
  66. union {
  67. //
  68. // Holds the source address when a datagram-read completes
  69. //
  70. SOCKADDR_IN ReadAddress;
  71. //
  72. // Holds the destination address while a datagram-send is in progress
  73. //
  74. SOCKADDR_IN WriteAddress;
  75. //
  76. // Holds the remote address while a connect is in progress
  77. //
  78. SOCKADDR_IN ConnectAddress;
  79. //
  80. // Holds the state of a multi-request read or write
  81. //
  82. struct {
  83. ULONG UserFlags;
  84. ULONG BytesToTransfer;
  85. ULONG TransferOffset;
  86. };
  87. };
  88. //
  89. // Upon completion of an I/O request, the error-code, byte-count,
  90. // and data-bytes for the request
  91. //
  92. ULONG ErrorCode;
  93. ULONG BytesTransferred;
  94. UCHAR Buffer[NH_BUFFER_SIZE];
  95. } NH_BUFFER, *PNH_BUFFER;
  96. #define NH_ALLOCATE_BUFFER() \
  97. reinterpret_cast<PNH_BUFFER>(NH_ALLOCATE(sizeof(NH_BUFFER)))
  98. #define NH_FREE_BUFFER(b) NH_FREE(b)
  99. //
  100. // BUFFER-MANAGEMENT ROUTINES (alphabetically)
  101. //
  102. #define NhAcquireBuffer() NhAcquireFixedLengthBuffer()
  103. PNH_BUFFER
  104. NhAcquireFixedLengthBuffer(
  105. VOID
  106. );
  107. PNH_BUFFER
  108. NhAcquireVariableLengthBuffer(
  109. ULONG Length
  110. );
  111. PNH_BUFFER
  112. NhDuplicateBuffer(
  113. PNH_BUFFER Bufferp
  114. );
  115. ULONG
  116. NhInitializeBufferManagement(
  117. VOID
  118. );
  119. VOID
  120. NhReleaseBuffer(
  121. PNH_BUFFER Bufferp
  122. );
  123. VOID
  124. NhShutdownBufferManagement(
  125. VOID
  126. );
  127. #endif // _NATHLP_BUFFER_H_