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.

160 lines
4.9 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2001-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: socketdata.h
  6. * Content: Socket list that can be shared between DPNWSOCK service provider interfaces.
  7. *
  8. *
  9. * History:
  10. * Date By Reason
  11. * ==== == ======
  12. * 10/25/2001 vanceo Extracted from spdata.h
  13. ***************************************************************************/
  14. #ifndef __SOCKETDATA_H__
  15. #define __SOCKETDATA_H__
  16. //**********************************************************************
  17. // Constant definitions
  18. //**********************************************************************
  19. //**********************************************************************
  20. // Macro definitions
  21. //**********************************************************************
  22. //**********************************************************************
  23. // Structure definitions
  24. //**********************************************************************
  25. //**********************************************************************
  26. // Class definitions
  27. //**********************************************************************
  28. //
  29. // class for information used by the provider
  30. //
  31. class CSocketData
  32. {
  33. public:
  34. #undef DPF_MODNAME
  35. #define DPF_MODNAME "CSocketData::AddRef"
  36. LONG AddRef(void)
  37. {
  38. LONG lResult;
  39. lResult = DNInterlockedIncrement(const_cast<LONG*>(&m_lRefCount));
  40. DPFX(DPFPREP, 9, "(0x%p) Refcount = %i.", this, lResult);
  41. return lResult;
  42. }
  43. #undef DPF_MODNAME
  44. #define DPF_MODNAME "CSocketData::Release"
  45. LONG Release(void)
  46. {
  47. LONG lResult;
  48. DNASSERT(m_lRefCount != 0);
  49. lResult = DNInterlockedDecrement(const_cast<LONG*>(&m_lRefCount));
  50. if (lResult == 0)
  51. {
  52. DPFX(DPFPREP, 3, "(0x%p) Refcount = 0, waiting for shutdown event.", this);
  53. IDirectPlay8ThreadPoolWork_WaitWhileWorking(m_pThreadPool->GetDPThreadPoolWork(),
  54. HANDLE_FROM_DNHANDLE(m_hSocketPortShutdownEvent),
  55. 0);
  56. DPFX(DPFPREP, 9, "(0x%p) Releasing this object back to pool.", this);
  57. g_SocketDataPool.Release(this);
  58. }
  59. else
  60. {
  61. DPFX(DPFPREP, 9, "(0x%p) Refcount = %i.", this, lResult);
  62. }
  63. return lResult;
  64. }
  65. #undef DPF_MODNAME
  66. #define DPF_MODNAME "CSocketData::AddSocketPortRef"
  67. LONG AddSocketPortRef(void)
  68. {
  69. LONG lResult;
  70. lResult = DNInterlockedIncrement(const_cast<LONG*>(&m_lSocketPortRefCount));
  71. if (lResult == 1)
  72. {
  73. DPFX(DPFPREP, 3, "(0x%p) Refcount = 1, resetting socketport shutdown event.", this);
  74. DNResetEvent(m_hSocketPortShutdownEvent);
  75. }
  76. else
  77. {
  78. DPFX(DPFPREP, 9, "(0x%p) Refcount = %i, not resetting socketport shutdown event.", this, lResult);
  79. }
  80. return lResult;
  81. }
  82. #undef DPF_MODNAME
  83. #define DPF_MODNAME "CSocketData::DecSocketPortRef"
  84. LONG DecSocketPortRef(void)
  85. {
  86. LONG lResult;
  87. DNASSERT(m_lSocketPortRefCount != 0);
  88. lResult = DNInterlockedDecrement(const_cast<LONG*>(&m_lSocketPortRefCount));
  89. if (lResult == 0)
  90. {
  91. DPFX(DPFPREP, 3, "(0x%p) Refcount = 0, setting socketport shutdown event.", this);
  92. DNSetEvent(m_hSocketPortShutdownEvent);
  93. }
  94. else
  95. {
  96. DPFX(DPFPREP, 9, "(0x%p) Refcount = %i, not setting socketport shutdown event.", this, lResult);
  97. }
  98. return lResult;
  99. }
  100. inline void Lock(void) { DNEnterCriticalSection(&m_csLock); }
  101. inline void Unlock(void) { DNLeaveCriticalSection(&m_csLock); }
  102. #ifdef DPNBUILD_ONLYONEADAPTER
  103. inline CBilink * GetSocketPorts(void) { return &m_blSocketPorts; }
  104. #else // ! DPNBUILD_ONLYONEADAPTER
  105. inline CBilink * GetAdapters(void) { return &m_blAdapters; }
  106. #endif // ! DPNBUILD_ONLYONEADAPTER
  107. BOOL FindSocketPort(const CSocketAddress * const pSocketAddress, CSocketPort ** const ppSocketPort );
  108. //
  109. // pool functions
  110. //
  111. static BOOL PoolAllocFunction(void * pvItem, void * pvContext);
  112. static void PoolInitFunction(void * pvItem, void * pvContext);
  113. static void PoolReleaseFunction(void * pvItem);
  114. static void PoolDeallocFunction(void * pvItem);
  115. private:
  116. BYTE m_Sig[4]; // debugging signature ('SODT')
  117. volatile LONG m_lRefCount; // reference count
  118. CThreadPool * m_pThreadPool; // pointer to thread pool used
  119. #ifndef DPNBUILD_ONLYONETHREAD
  120. DNCRITICAL_SECTION m_csLock; // lock
  121. #endif // !DPNBUILD_ONLYONETHREAD
  122. #ifdef DPNBUILD_ONLYONEADAPTER
  123. CBilink m_blSocketPorts; // list of active socket ports
  124. #else // ! DPNBUILD_ONLYONEADAPTER
  125. CBilink m_blAdapters; // list of active adapters (upon which socket ports are bound)
  126. #endif // ! DPNBUILD_ONLYONEADAPTER
  127. volatile LONG m_lSocketPortRefCount; // number of socket ports that have references on the object
  128. DNHANDLE m_hSocketPortShutdownEvent; // event to set when all socketports have unbound
  129. };
  130. #undef DPF_MODNAME
  131. #endif // __SOCKETDATA_H__