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.

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