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.

252 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 1998, Microsoft Corporation
  3. Module Name:
  4. socket.h
  5. Abstract:
  6. This module contains declarations for socket-management.
  7. The routines declared here operate asynchronously on sockets
  8. associated with an I/O completion port. They are also integrated
  9. with the component-reference object, which may optionally be used
  10. by callers to control the number of outstanding entries into a component's
  11. address-space. (See 'COMPREF.H'.)
  12. Author:
  13. Abolade Gbadegesin (aboladeg) 2-Mar-1998
  14. Revision History:
  15. Abolade Gbadegesin (aboladeg) 23-May-1999
  16. Added support for stream sockets.
  17. --*/
  18. #ifndef _NATHLP_SOCKET_H_
  19. #define _NATHLP_SOCKET_H_
  20. #define INET_NTOA(x) inet_ntoa(*(struct in_addr*)&(x))
  21. //
  22. // BOOLEAN
  23. // NhIsFatalSocketError(
  24. // ULONG Error
  25. // );
  26. //
  27. // Determines whether a request may be reissued on a socket,
  28. // given the error-code from the previous issuance of the request.
  29. // This macro is arranged to branch on the most common error-codes first.
  30. //
  31. #define \
  32. NhIsFatalSocketError( \
  33. _Error \
  34. ) \
  35. ((_Error) != ERROR_OPERATION_ABORTED && \
  36. ((_Error) == WSAEDISCON || \
  37. (_Error) == WSAECONNRESET || \
  38. (_Error) == WSAETIMEDOUT || \
  39. (_Error) == WSAENETDOWN || \
  40. (_Error) == WSAENOTSOCK || \
  41. (_Error) == WSAESHUTDOWN || \
  42. (_Error) == WSAECONNABORTED))
  43. typedef class _CNhSock : public virtual GENERIC_NODE
  44. {
  45. public:
  46. _CNhSock();
  47. _CNhSock(SOCKET iSocket);
  48. ~_CNhSock();
  49. void ComponentCleanUpRoutine(void);
  50. virtual void StopSync(void);
  51. virtual PCHAR GetObjectName() { return ObjectNamep;}
  52. SOCKET GetSock() { return Socket;};
  53. VOID SetSock(SOCKET inSock) { Socket = inSock;};
  54. ULONG
  55. NhAcceptStreamSocket(
  56. PCOMPONENT_SYNC Component,
  57. class _CNhSock * AcceptedSocketp OPTIONAL,
  58. PNH_BUFFER Bufferp OPTIONAL,
  59. PNH_COMPLETION_ROUTINE AcceptCompletionRoutine,
  60. PVOID Context,
  61. PVOID Context2
  62. );
  63. ULONG
  64. NhConnectStreamSocket(
  65. PCOMPONENT_SYNC Component,
  66. ULONG Address,
  67. USHORT Port,
  68. PNH_BUFFER Bufferp OPTIONAL,
  69. PNH_COMPLETION_ROUTINE ConnectCompletionRoutine,
  70. PNH_COMPLETION_ROUTINE CloseNotificationRoutine OPTIONAL,
  71. PVOID Context,
  72. PVOID Context2
  73. );
  74. ULONG
  75. NhCreateDatagramSocket(
  76. ULONG Address,
  77. USHORT Port,
  78. OUT SOCKET* Socketp
  79. );
  80. ULONG
  81. NhCreateStreamSocket(
  82. ULONG Address OPTIONAL, // may be INADDR_NONE
  83. USHORT Port OPTIONAL,
  84. OUT SOCKET* Socketp
  85. );
  86. #define NhDeleteDatagramSocket(s) NhDeleteSocket(s)
  87. #define NhDeleteStreamSocket(s) NhDeleteSocket(s)
  88. VOID
  89. NhDeleteSocket(
  90. SOCKET Socket
  91. );
  92. VOID NhDeleteSocket() \
  93. {if (this->Socket != INVALID_SOCKET) {closesocket(this->Socket);};}
  94. ULONG
  95. NhNotifyOnCloseStreamSocket(
  96. PCOMPONENT_SYNC Component,
  97. PNH_BUFFER Bufferp OPTIONAL,
  98. PNH_COMPLETION_ROUTINE CloseNotificationRoutine,
  99. PVOID Context,
  100. PVOID Context2
  101. );
  102. VOID
  103. NhQueryAcceptEndpoints(
  104. PUCHAR AcceptBuffer,
  105. PULONG LocalAddress OPTIONAL,
  106. PUSHORT LocalPort OPTIONAL,
  107. PULONG RemoteAddress OPTIONAL,
  108. PUSHORT RemotePort OPTIONAL
  109. );
  110. ULONG
  111. NhQueryAddressSocket();
  112. ULONG
  113. NhQueryLocalEndpointSocket(
  114. PULONG Address OPTIONAL,
  115. PUSHORT Port OPTIONAL
  116. );
  117. USHORT
  118. NhQueryPortSocket();
  119. ULONG
  120. NhQueryRemoteEndpointSocket(
  121. PULONG Address OPTIONAL,
  122. PUSHORT Port OPTIONAL
  123. );
  124. ULONG
  125. NhReadDatagramSocket(
  126. PCOMPONENT_SYNC Component,
  127. PNH_BUFFER Bufferp OPTIONAL,
  128. PNH_COMPLETION_ROUTINE CompletionRoutine,
  129. PVOID Context,
  130. PVOID Context2
  131. );
  132. ULONG
  133. NhReadStreamSocket(
  134. PCOMPONENT_SYNC Component,
  135. PNH_BUFFER Bufferp OPTIONAL,
  136. ULONG Length,
  137. ULONG Offset,
  138. PNH_COMPLETION_ROUTINE CompletionRoutine,
  139. PVOID Context,
  140. PVOID Context2
  141. );
  142. ULONG
  143. NhWriteDatagramSocket(
  144. PCOMPONENT_SYNC Component,
  145. ULONG Address,
  146. USHORT Port,
  147. PNH_BUFFER Bufferp,
  148. ULONG Length,
  149. PNH_COMPLETION_ROUTINE CompletionRoutine,
  150. PVOID Context,
  151. PVOID Context2
  152. );
  153. ULONG
  154. NhWriteStreamSocket(
  155. PCOMPONENT_SYNC Component,
  156. PNH_BUFFER Bufferp,
  157. ULONG Length,
  158. ULONG Offset,
  159. PNH_COMPLETION_ROUTINE CompletionRoutine,
  160. PVOID Context,
  161. PVOID Context2
  162. );
  163. static VOID NTAPI
  164. NhpConnectOrCloseCallbackRoutine(
  165. PVOID Context,
  166. BOOLEAN WaitCompleted
  167. );
  168. static VOID NTAPI
  169. NhpCloseNotificationCallbackRoutine(
  170. PVOID Context,
  171. BOOLEAN WaitCompleted
  172. );
  173. static VOID WINAPI
  174. NhpIoCompletionRoutine(
  175. ULONG ErrorCode,
  176. ULONG BytesTransferred,
  177. LPOVERLAPPED Overlapped
  178. );
  179. static VOID APIENTRY
  180. NhpIoWorkerRoutine(
  181. PVOID Context
  182. );
  183. protected:
  184. SOCKET Socket;
  185. static const PCHAR ObjectNamep;
  186. // For Shared Sockets we should have ShareCounter
  187. } CNhSock, *PCNhSock;
  188. //
  189. // Utility functions
  190. //
  191. ULONG InterfaceForDestination(ULONG DestIp);
  192. #endif // _NATHLP_SOCKET_H_