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.

160 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. class _CNhSock;
  42. typedef struct _NH_BUFFER {
  43. union {
  44. LIST_ENTRY Link;
  45. NH_BUFFER_TYPE Type;
  46. };
  47. //
  48. // The socket associated with the buffer's most recent I/O request
  49. //
  50. class _CNhSock * Socketp;
  51. //
  52. // Completion routine and contexts for the buffer's most recent I/O request
  53. //
  54. PNH_COMPLETION_ROUTINE CompletionRoutine;
  55. PVOID Context;
  56. PVOID Context2;
  57. //
  58. // Passed as the system context area for any I/O using the buffer
  59. //
  60. OVERLAPPED Overlapped;
  61. //
  62. // Upon completion of a receive, the receive-flags and source-address
  63. // length for the message read
  64. //
  65. ULONG ReceiveFlags;
  66. ULONG AddressLength;
  67. union {
  68. //
  69. // Holds the source address when a datagram-read completes
  70. //
  71. SOCKADDR_IN ReadAddress;
  72. //
  73. // Holds the destination address while a datagram-send is in progress
  74. //
  75. SOCKADDR_IN WriteAddress;
  76. //
  77. // Holds the remote address while a connect is in progress
  78. //
  79. SOCKADDR_IN ConnectAddress;
  80. //
  81. // Holds the state of a multi-request read or write
  82. //
  83. struct {
  84. ULONG UserFlags;
  85. ULONG BytesToTransfer;
  86. ULONG TransferOffset;
  87. };
  88. };
  89. //
  90. // Upon completion of an I/O request, the error-code, byte-count,
  91. // and data-bytes for the request
  92. //
  93. ULONG ErrorCode;
  94. ULONG BytesTransferred;
  95. UCHAR Buffer[NH_BUFFER_SIZE];
  96. } NH_BUFFER, *PNH_BUFFER;
  97. #define NH_ALLOCATE_BUFFER() \
  98. reinterpret_cast<PNH_BUFFER>(NH_ALLOCATE(sizeof(NH_BUFFER)))
  99. #define NH_FREE_BUFFER(b) NH_FREE(b)
  100. //
  101. // BUFFER-MANAGEMENT ROUTINES (alphabetically)
  102. //
  103. #define NhAcquireBuffer() NhAcquireFixedLengthBuffer()
  104. PNH_BUFFER
  105. NhAcquireFixedLengthBuffer(
  106. VOID
  107. );
  108. PNH_BUFFER
  109. NhAcquireVariableLengthBuffer(
  110. ULONG Length
  111. );
  112. PNH_BUFFER
  113. NhDuplicateBuffer(
  114. PNH_BUFFER Bufferp
  115. );
  116. ULONG
  117. NhInitializeBufferManagement(
  118. VOID
  119. );
  120. VOID
  121. NhReleaseBuffer(
  122. PNH_BUFFER Bufferp
  123. );
  124. VOID
  125. NhShutdownBufferManagement(
  126. VOID
  127. );
  128. #endif // _NATHLP_BUFFER_H_