Leaked source code of windows server 2003
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.

269 lines
7.9 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. ARPDINT.H
  5. Abstract:
  6. Include file for Another Reliable Protocol internal.
  7. Author:
  8. Aaron Ogus (aarono)
  9. Environment:
  10. Win32/COM
  11. Revision History:
  12. Date Author Description
  13. ====== ====== ============================================================
  14. 12/10/96 aarono Original
  15. 2/16/98 aarono Don't patch for Protocol, DPLAY now calls direct.
  16. 6/6/98 aarono Turn on throttling and windowing
  17. 2/12/00 aarono Concurrency issues, fix VOL usage and Refcount
  18. --*/
  19. #ifndef _ARPDINT_H_
  20. #define _ARPDINT_H_
  21. #include <dplay.h>
  22. #include "arpd.h"
  23. #include "bilink.h"
  24. #include "arpstruc.h"
  25. #include "protocol.h"
  26. #include "bufmgr.h"
  27. #include "handles.h"
  28. // Macros for converting too and from 24.8 fixed point.
  29. #define Fp(_x) ((_x)<<8)
  30. #define unFp(_x)((_x)>>8)
  31. typedef enum _PROTOCOL_State {
  32. Initializing=1,
  33. Running,
  34. ShuttingDown,
  35. ShutDown
  36. } PROTOCOL_State;
  37. #define MAX_THREADS 16
  38. typedef struct PROTOCOL {
  39. //
  40. // Service Provider info - at top so DPLAY can access easily through protocol ptr.
  41. //
  42. IDirectPlaySP * m_lpISP; // used by SP to call back into DirectPlay
  43. DWORD m_dwSPMaxFrame;
  44. DWORD m_dwSPMaxGuaranteed;
  45. DWORD m_dwSPHeaderSize;
  46. CRITICAL_SECTION m_SPLock; // lock calls to SP on our own, avoids deadlocks.
  47. //
  48. // Protocol Info
  49. //
  50. VOL UINT m_cRef; // Refcount.
  51. CRITICAL_SECTION m_ObjLock; // lock for this object.
  52. VOL PROTOCOL_State m_eState; // State of object
  53. VOL LPDPLAYI_DPLAY m_lpDPlay; // backpointer to DPLAY object.
  54. // Handle Table
  55. VOLLPMYHANDLETABLE lpHandleTable;
  56. CRITICAL_SECTION csHandleTable;
  57. // Cached DPLAY info.
  58. DWORD m_dwIDKey; // to unlock DPID's
  59. //
  60. // Threads
  61. //
  62. HANDLE m_hSendThread[MAX_THREADS]; // send thread handles (0->nSendThreads)
  63. DWORD m_dwSendThreadId[MAX_THREADS];// send thread ids (0->nSendThreads)
  64. VOL UINT m_nSendThreads; // number of send threads.
  65. VOL HANDLE m_hSendEvent; // kick send until nothing to send.
  66. //
  67. // Multi-media timer capabilities
  68. //
  69. TIMECAPS m_timecaps; // {.wPeriodMin .wPeriodMax (ms)}
  70. //
  71. // SESSIONion Handles
  72. //
  73. CRITICAL_SECTION m_SessionLock;
  74. VOL UINT m_nSessions;
  75. VOL UINT m_SessionListSize;
  76. VOL PSESSION (*m_pSessions)[];
  77. VOL PSESSION m_pServerPlayerSession; // Short circuit to index 0xFFFE
  78. //
  79. // Priority Queue
  80. //
  81. VOL DWORD m_dwBytesPending;
  82. VOL DWORD m_dwMessagesPending;
  83. CRITICAL_SECTION m_SendQLock; // Locks the Priority Queue.
  84. BILINK m_GSendQ; // Packet Queue in priority order.
  85. VOL BOOL m_bRescanQueue; // Used for force GetNextMessageToSend to restart
  86. CRITICAL_SECTION m_RcvQLock; // All completed receives lock. (locks on SESSION too).
  87. BILINK m_GlobalRcvQ; // All receives queued here, (also on each session).
  88. //
  89. // Receive Descriptor Management - per instance because of SPHeader length.
  90. //
  91. VOL PRECEIVE pRcvDescPool;
  92. VOL UINT nRcvDescsAllocated; // Number Allocated
  93. VOL UINT nRcvDescsInUse; // Number currently in use
  94. VOL UINT nMaxRcvDescsInUse; // Maximum number in use since last TICK.
  95. CRITICAL_SECTION RcvDescLock;
  96. VOL LONG fInRcvDescTick;
  97. } PROTOCOL, *PPROTOCOL;
  98. // PROTOCOL.C
  99. HRESULT WINAPI ProtocolSend(LPDPSP_SENDDATA pSendData);
  100. HRESULT WINAPI ProtocolCreatePlayer(LPDPSP_CREATEPLAYERDATA pCreatePlayerData);
  101. HRESULT WINAPI ProtocolDeletePlayer(LPDPSP_DELETEPLAYERDATA pDeletePlayerData);
  102. HRESULT WINAPI ProtocolGetCaps(LPDPSP_GETCAPSDATA pGetCapsData);
  103. HRESULT WINAPI ProtocolShutdown(void);
  104. HRESULT WINAPI ProtocolShutdownEx(LPDPSP_SHUTDOWNDATA pShutdownData);
  105. //
  106. // SENDPOOL.CPP
  107. //
  108. VOID InitSendDescs(VOID);
  109. VOID FiniSendDescs(VOID);
  110. PSEND GetSendDesc(VOID);
  111. VOID ReleaseSendDesc(PSEND pSend);
  112. //
  113. // STATPOOL.CPP
  114. //
  115. VOID InitSendStats(VOID);
  116. VOID FiniSendStats(VOID);
  117. PSENDSTAT GetSendStat(VOID);
  118. VOID ReleaseSendStat(PSENDSTAT pSendStat);
  119. //
  120. // RCVPOOL.CPP
  121. //
  122. VOID InitRcvDescs(PPROTOCOL pProtocol);
  123. VOID FiniRcvDescs(PPROTOCOL pProtocol);
  124. PRECEIVE GetRcvDesc(PPROTOCOL pProtocol);
  125. VOID ReleaseRcvDesc(PPROTOCOL pProtocol, PRECEIVE pReceive);
  126. // FRAMEBUF.CPP
  127. VOID InitFrameBuffers(VOID);
  128. VOID FiniFrameBuffers(VOID);
  129. VOID FreeFrameBuffer(PBUFFER pBuffer);
  130. PBUFFER GetFrameBuffer(UINT MaxFrame);
  131. VOID ReleaseFrameBufferMemory(PUCHAR pFrame);
  132. // SEND.C
  133. VOID UpdateSendTime(PSESSION pSession, DWORD Len, DWORD tm, BOOL fAbsolute);
  134. HRESULT SendHandler(PPROTOCOL pProt);
  135. VOID BuildHeader(PSEND pSend, pPacket1 pFrame, UINT shift, DWORD tm);
  136. ULONG WINAPI SendThread(LPVOID pProt);
  137. INT IncSendRef(PSEND pSend);
  138. INT DecSendRef(PPROTOCOL pProt, PSEND pSend);
  139. BOOL AdvanceSend(PSEND pSend, UINT FrameDataLen);
  140. VOID CancelRetryTimer(PSEND pSend);
  141. VOID DoSendCompletion(PSEND pSend, INT Status);
  142. HRESULT Send(
  143. PPROTOCOL pProtocol,
  144. DPID idFrom,
  145. DPID idTo,
  146. DWORD dwSendFlags,
  147. LPVOID pBuffers,
  148. DWORD dwBufferCount,
  149. DWORD dwSendPri,
  150. DWORD dwTimeOut,
  151. LPVOID lpvUserID,
  152. LPDWORD lpdwMsgID,
  153. BOOL bSendEx, // called from SendEx.
  154. PASYNCSENDINFO pAsyncInfo
  155. );
  156. HRESULT ISend(
  157. PPROTOCOL pProtocol,
  158. PSESSION pSession,
  159. PSEND pSend
  160. );
  161. HRESULT QueueSendOnSession(
  162. PPROTOCOL pProtocol, PSESSION pSession, PSEND pSend
  163. );
  164. UINT CopyDataToFrame(
  165. PUCHAR pFrameData,
  166. UINT FrameDataLen,
  167. PSEND pSend,
  168. UINT nAhead);
  169. ULONG WINAPI SendThread(LPVOID pProt);
  170. HRESULT ReliableSend(PPROTOCOL pProtocol, PSEND pSend);
  171. BOOL AdvanceSend(PSEND pSend, UINT AckedLen);
  172. HRESULT DGSend(PPROTOCOL pProtocol, PSEND pSend);
  173. BOOL DGCompleteSend(PSEND pSend);
  174. HRESULT SystemSend(PPROTOCOL pProtocol, PSEND pSend);
  175. PSEND GetNextMessageToSend(PPROTOCOL pProtocol);
  176. VOID TimeOutSession(PSESSION pSession);
  177. INT AddSendRef(PSEND pSend, UINT count);
  178. extern CRITICAL_SECTION g_SendTimeoutListLock;
  179. extern BILINK g_BilinkSendTimeoutList;
  180. //RECEIVE.C
  181. UINT CommandReceive(PPROTOCOL pProt, CMDINFO *pCmdInfo, PBUFFER pBuffer);
  182. VOID ProtocolReceive(PPROTOCOL pProtocol, WORD idFrom, WORD idTo, PBUFFER pRcvBuffer, LPVOID pvSPHeader);
  183. VOID FreeReceive(PPROTOCOL pProtocol, PRECEIVE pReceive);
  184. VOID InternalSendComplete(PVOID Context, UINT Status);
  185. //SESSION.C
  186. LPDPLAYI_PLAYER pPlayerFromId(PPROTOCOL pProtocol, DPID idPlayer);
  187. HRESULT CreateNewSession(PPROTOCOL pProtocol, DPID idPlayer);
  188. PSESSION GetSession(PPROTOCOL pProtocol, DPID idPlayer);
  189. PSESSION GetSysSession(PPROTOCOL pProtocol, DPID idPlayer);
  190. PSESSION GetSysSessionByIndex(PPROTOCOL pProtocol, DWORD index);
  191. DPID GetDPIDByIndex(PPROTOCOL pProtocol, DWORD index);
  192. WORD GetIndexByDPID(PPROTOCOL pProtocol, DPID dpid);
  193. INT DecSessionRef(PSESSION pSession);
  194. //BUFGMGR.C
  195. VOID InitBufferManager(VOID);
  196. VOID FiniBufferManager(VOID);
  197. UINT MemDescTotalSize(PMEMDESC pMemDesc, UINT nDesc);
  198. PDOUBLEBUFFER GetDoubleBuffer(UINT nBytes);
  199. PBUFFER GetDoubleBufferAndCopy(PMEMDESC pMemDesc, UINT nDesc);
  200. VOID FreeDoubleBuffer(PBUFFER pBuffer);
  201. PBUFFER BuildBufferChain(PMEMDESC pMemDesc, UINT nDesc);
  202. VOID FreeBufferChain(PBUFFER pBuffer);
  203. VOID FreeBufferChainAndMemory(PBUFFER pBuffer);
  204. UINT BufferChainTotalSize(PBUFFER pBuffer);
  205. //STATS.C
  206. VOID InitSessionStats(PSESSION pSession);
  207. VOID UpdateSessionStats(PSESSION pSession, PSENDSTAT pStat, PCMDINFO pCmdInfo, BOOL fBadDrop);
  208. VOID UpdateSessionSendStats(PSESSION pSession, PSEND pSend, PCMDINFO pCmdInfo, BOOL fBadDrop);
  209. #define SAR_FAIL 0
  210. #define SAR_ACK 1
  211. #define SAR_NACK 2
  212. UINT SendAppropriateResponse(PPROTOCOL pProt, PSESSION pSession, CMDINFO *pCmdInfo, PRECEIVE pReceive);
  213. #endif