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.

308 lines
7.3 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. socket.h
  5. Abstract:
  6. Contains macros, prototypes and structures for socket.c
  7. Author:
  8. Richard L Firth (rfirth) 25-Oct-1993
  9. Revision History:
  10. 25-Oct-1993 rfirth
  11. Created
  12. --*/
  13. #define ARBITRARY_CONNECTION_NUMBER 0x6c8e
  14. //
  15. // forward declarations
  16. //
  17. typedef struct _FIFO *LPFIFO;
  18. typedef struct _XECB *LPXECB;
  19. typedef struct _XECB_QUEUE *LPXECB_QUEUE;
  20. typedef struct _SOCKET_INFO* LPSOCKET_INFO;
  21. typedef struct _CONNECTION_INFO *LPCONNECTION_INFO;
  22. //
  23. // FIFO - standard single-linked FIFO queue structure
  24. //
  25. typedef struct _FIFO {
  26. LPVOID Head;
  27. LPVOID Tail;
  28. } FIFO;
  29. //
  30. // function type for cancelling XECB/ECB
  31. //
  32. typedef BYTE (*ECB_CANCEL_ROUTINE)(LPXECB);
  33. //
  34. // QUEUE_ID - indicator of which queue an ECB is on
  35. //
  36. typedef enum {
  37. NO_QUEUE = 0x10cadd1e,
  38. ASYNC_COMPLETION_QUEUE = 0xCC5055C0, // arbitrary numbers make life interesting
  39. TIMER_QUEUE,
  40. SOCKET_LISTEN_QUEUE,
  41. SOCKET_SEND_QUEUE,
  42. SOCKET_HEADER_QUEUE, // special queue for small ECBs that cannot hold data
  43. CONNECTION_CONNECT_QUEUE,
  44. CONNECTION_ACCEPT_QUEUE,
  45. CONNECTION_SEND_QUEUE,
  46. CONNECTION_LISTEN_QUEUE
  47. } QUEUE_ID;
  48. //
  49. // XECB - our copy of the ECB (IPX or AES)
  50. //
  51. typedef struct _XECB {
  52. LPXECB Next;
  53. LPECB Ecb; // points to ECB in DOS memory
  54. ECB_ADDRESS EcbAddress; // segmented address of ECB in DOS memory
  55. ESR_ADDRESS EsrAddress; // Event Service Routine in DOS memory
  56. LPBYTE Buffer; // address of 32-bit buffer
  57. LPBYTE Data; // moveable data pointer
  58. WORD FrameLength; // actual size of frame (from IPX/SPX header)
  59. WORD ActualLength; // same as FrameLength. Not decremented
  60. WORD Length; // length of 32-bit buffer
  61. WORD Ticks; // for AES
  62. WORD SocketNumber; // number of owning socket
  63. WORD Owner; // owning DOS Task ID
  64. DWORD TaskId; // owning Windows Task ID
  65. DWORD Flags; // see below
  66. QUEUE_ID QueueId; // identifies the queue for quick location
  67. LPVOID OwningObject; // which SOCKET_INFO or CONNECTION_INFO the queue is on
  68. DWORD RefCount; // the dreaded reference count
  69. } XECB;
  70. //
  71. // XECB flags
  72. //
  73. #define XECB_FLAG_AES 0x00000000
  74. #define XECB_FLAG_IPX 0x00000001
  75. #define XECB_FLAG_TEMPORARY_SOCKET 0x00000002
  76. #define XECB_FLAG_BUFFER_ALLOCATED 0x00000004
  77. #define XECB_FLAG_LISTEN 0x00000008
  78. #define XECB_FLAG_SEND 0x00000010
  79. #define XECB_FLAG_TIMER 0x00000020
  80. #define XECB_FLAG_ASYNC 0x00000040
  81. #define XECB_FLAG_FIRST_RECEIVE 0x00000080
  82. #define XECB_FLAG_SPX 0x00000100
  83. #define XECB_FLAG_PROTMODE 0x00000200
  84. #define IS_PROT_MODE(p) (((p)->Flags & XECB_FLAG_PROTMODE) ? TRUE : FALSE)
  85. //
  86. // XECB_QUEUE - queue of XECBs
  87. //
  88. typedef struct _XECB_QUEUE {
  89. LPXECB Head;
  90. LPXECB Tail;
  91. } XECB_QUEUE;
  92. //
  93. // SOCKET_INFO - maintains info about IPX sockets
  94. //
  95. typedef struct _SOCKET_INFO {
  96. LPSOCKET_INFO Next;
  97. WORD SocketNumber; // big-endian socket (bound port)
  98. WORD Owner; // DOS PDB
  99. DWORD TaskId; // Windows owner
  100. SOCKET Socket; // the WinSock socket handle
  101. DWORD Flags;
  102. BOOL LongLived; // TRUE if keep-alive when app dies
  103. BOOL SpxSocket; // TRUE if socket opened for SPX
  104. DWORD PendingSends; // used by cancel
  105. DWORD PendingListens; // used by cancel
  106. //
  107. // ListenQueue is used for IPXListenForPacket and SPXListenForSequencedPacket
  108. //
  109. XECB_QUEUE ListenQueue; // pool of listening ECBs against this socket
  110. //
  111. // SendQueue is used by IPX for IPXSendPacket
  112. //
  113. XECB_QUEUE SendQueue; // queue of pending send ECBs against this socket
  114. //
  115. // HeaderQueue is used to hold small ECBs that can only take header info.
  116. // We have this separate queue to make sure that we do not put ECBs that
  117. // really cant accept any data into the Listen Queue.
  118. //
  119. XECB_QUEUE HeaderQueue; // pool of header ECBs against this socket
  120. LPCONNECTION_INFO Connections;
  121. } SOCKET_INFO;
  122. #define SOCKET_FLAG_LISTENING 0x00000001
  123. #define SOCKET_FLAG_SENDING 0x00000002
  124. #define SOCKET_FLAG_TEMPORARY 0x80000000
  125. //
  126. // CONNECTION_INFO - maintains info about SPX sockets
  127. //
  128. typedef struct _CONNECTION_INFO {
  129. LPCONNECTION_INFO Next; // next CONNECTION_INFO by OwningSocket
  130. LPCONNECTION_INFO List; // all CONNECTION_INFO are linked together
  131. LPSOCKET_INFO OwningSocket; // back-pointer to SOCKET_INFO
  132. SOCKET Socket; // handle to socket
  133. DWORD TaskId; // identifies windows task/owner
  134. WORD ConnectionId; // analogous to SocketNumber
  135. BYTE Flags;
  136. BYTE State;
  137. XECB_QUEUE ConnectQueue; // outgoing connections being made
  138. XECB_QUEUE AcceptQueue; // waiting for incoming connections
  139. XECB_QUEUE SendQueue; // packet sends on this connection
  140. XECB_QUEUE ListenQueue; // partially complete receive
  141. BYTE RemoteNode[6];
  142. WORD RemoteConnectionId;
  143. } CONNECTION_INFO;
  144. //
  145. // CONNECTION_INFO Flag field values
  146. //
  147. #define CF_1ST_RECEIVE 0x80 // hack-o-rama till NWLink timing problem fixed
  148. //
  149. // CONNECTION_INFO State field values
  150. //
  151. #define CI_WAITING 0x01
  152. #define CI_STARTING 0x02
  153. #define CI_ESTABLISHED 0x03
  154. #define CI_TERMINATING 0x04
  155. //
  156. // one-line function macros
  157. //
  158. #define AllocateSocket() (LPSOCKET_INFO)LocalAlloc(LPTR, sizeof(SOCKET_INFO))
  159. #define DeallocateSocket(p) FREE_OBJECT(p)
  160. //
  161. // SocketType parameter for CreateSocket
  162. //
  163. typedef enum {
  164. SOCKET_TYPE_IPX,
  165. SOCKET_TYPE_SPX
  166. } SOCKET_TYPE;
  167. //
  168. // function prototypes
  169. //
  170. int
  171. CreateSocket(
  172. IN SOCKET_TYPE SocketType,
  173. IN OUT ULPWORD pSocketNumber,
  174. OUT SOCKET* pSocket
  175. );
  176. LPSOCKET_INFO
  177. AllocateTemporarySocket(
  178. VOID
  179. );
  180. VOID
  181. QueueSocket(
  182. IN LPSOCKET_INFO pSocketInfo
  183. );
  184. LPSOCKET_INFO
  185. DequeueSocket(
  186. IN LPSOCKET_INFO pSocketInfo
  187. );
  188. LPSOCKET_INFO
  189. FindSocket(
  190. IN WORD SocketNumber
  191. );
  192. LPSOCKET_INFO
  193. FindActiveSocket(
  194. IN LPSOCKET_INFO pSocketInfo
  195. );
  196. int
  197. ReopenSocket(
  198. LPSOCKET_INFO pSocketInfo
  199. );
  200. VOID
  201. KillSocket(
  202. IN LPSOCKET_INFO pSocketInfo
  203. );
  204. VOID
  205. KillShortLivedSockets(
  206. IN WORD Owner
  207. );
  208. LPCONNECTION_INFO
  209. AllocateConnection(
  210. LPSOCKET_INFO pSocketInfo
  211. );
  212. VOID
  213. DeallocateConnection(
  214. IN LPCONNECTION_INFO pConnectionInfo
  215. );
  216. LPCONNECTION_INFO
  217. FindConnection(
  218. IN WORD ConnectionId
  219. );
  220. VOID
  221. QueueConnection(
  222. IN LPSOCKET_INFO pSocketInfo,
  223. IN LPCONNECTION_INFO pConnectionInfo
  224. );
  225. LPCONNECTION_INFO
  226. DequeueConnection(
  227. IN LPSOCKET_INFO pSocketInfo,
  228. IN LPCONNECTION_INFO pConnectionInfo
  229. );
  230. VOID
  231. KillConnection(
  232. IN LPCONNECTION_INFO pConnectionInfo
  233. );
  234. VOID
  235. AbortOrTerminateConnection(
  236. IN LPCONNECTION_INFO pConnectionInfo,
  237. IN BYTE CompletionCode
  238. );
  239. VOID
  240. CheckPendingSpxRequests(
  241. BOOL *pfOperationPerformed
  242. );