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.

194 lines
5.6 KiB

  1. /************************************************************************
  2. * *
  3. * INTEL CORPORATION PROPRIETARY INFORMATION *
  4. * *
  5. * This software is supplied under the terms of a license *
  6. * agreement or non-disclosure agreement with Intel Corporation *
  7. * and may not be copied or disclosed except in accordance *
  8. * with the terms of that agreement. *
  9. * *
  10. * Copyright (C) 1997 Intel Corp. All Rights Reserved *
  11. * *
  12. * $Archive: S:/STURGEON/SRC/GKI/VCS/postrecv.cpv $
  13. * *
  14. * $Revision: 1.8 $
  15. * $Date: 13 Feb 1997 15:05:20 $
  16. * *
  17. * $Author: unknown $
  18. * *
  19. * $Log: S:/STURGEON/SRC/GKI/VCS/postrecv.cpv $
  20. //
  21. // Rev 1.8 13 Feb 1997 15:05:20 unknown
  22. // Moved CGatekeeper::Unlock to end of PostRecv thread to avoid shutdown err
  23. //
  24. // Rev 1.7 12 Feb 1997 01:12:08 CHULME
  25. // Redid thread synchronization to use Gatekeeper.Lock
  26. //
  27. // Rev 1.6 24 Jan 1997 18:36:24 CHULME
  28. // Reverted to rev 1.4
  29. //
  30. // Rev 1.4 17 Jan 1997 09:02:32 CHULME
  31. // Changed reg.h to gkreg.h to avoid name conflict with inc directory
  32. //
  33. // Rev 1.3 10 Jan 1997 16:15:54 CHULME
  34. // Removed MFC dependency
  35. //
  36. // Rev 1.2 22 Nov 1996 15:21:24 CHULME
  37. // Added VCS log to the header
  38. *************************************************************************/
  39. // postrecv.cpp : Provides the secondary thread implementation
  40. //
  41. #include "precomp.h"
  42. #include "gkicom.h"
  43. #include "dspider.h"
  44. #include "dgkilit.h"
  45. #include "DGKIPROT.H"
  46. #include "gksocket.h"
  47. #include "GKREG.H"
  48. #include "GATEKPR.H"
  49. #include "h225asn.h"
  50. #include "coder.hpp"
  51. #include "dgkiext.h"
  52. #ifdef _DEBUG
  53. #undef THIS_FILE
  54. static char THIS_FILE[] = __FILE__;
  55. #endif
  56. void
  57. PostReceive(void *pv)
  58. {
  59. // ABSTRACT: This function is invoked in a separate thread to
  60. // post a receive on the associated socket. When a datagram
  61. // arrives, this function will decode it and send it
  62. // to the PDUHandler. If the PDUHandler doesn't instruct
  63. // this thread to exit (with a non-zero return code), this
  64. // function will post another receive.
  65. // AUTHOR: Colin Hulme
  66. char szBuffer[512];
  67. int nRet;
  68. ASN1_BUF Asn1Buf;
  69. DWORD dwErrorCode;
  70. RasMessage *pRasMessage;
  71. #ifdef _DEBUG
  72. char szGKDebug[80];
  73. #endif
  74. HRESULT hResult = GKI_OK;
  75. SPIDER_TRACE(SP_FUNC, "PostReceive(pv)\n", 0);
  76. ASSERT(g_pCoder);
  77. if ((g_pCoder == NULL) && (g_pGatekeeper == NULL))
  78. return;
  79. while ((hResult == GKI_OK) && g_pReg && H225ASN_Module)
  80. {
  81. g_pReg->LockSocket();
  82. nRet = g_pReg->m_pSocket->Receive(szBuffer, 512);
  83. g_pReg->UnlockSocket();
  84. g_pGatekeeper->Lock();
  85. if ((g_pReg == 0) || (H225ASN_Module == NULL))
  86. {
  87. SPIDER_TRACE(SP_THREAD, "PostReceive thread exiting\n", 0);
  88. g_pGatekeeper->Unlock();
  89. return;
  90. }
  91. if (nRet != SOCKET_ERROR)
  92. {
  93. if (fGKIEcho && (pEchoBuff != 0))
  94. {
  95. if (nEchoLen != nRet)
  96. {
  97. SPIDER_TRACE(SP_DEBUG, "*** Received buffer len != Sent buffer len ***\n", 0);
  98. }
  99. if (memcmp(szBuffer, pEchoBuff, nEchoLen) == 0)
  100. {
  101. SPIDER_TRACE(SP_DEBUG, "Received buffer = Sent buffer\n", 0);
  102. }
  103. else
  104. {
  105. SPIDER_TRACE(SP_DEBUG, "*** Received buffer != Sent buffer ***\n", 0);
  106. }
  107. SPIDER_TRACE(SP_NEWDEL, "del pEchoBuff = %X\n", pEchoBuff);
  108. delete pEchoBuff;
  109. pEchoBuff = 0;
  110. }
  111. else // Process incoming PDU
  112. {
  113. // Setup Asn1Buf for decoder and decode PDU
  114. Asn1Buf.length = nRet; // number of bytes received
  115. Asn1Buf.value = (unsigned char *)szBuffer;
  116. dwErrorCode = g_pCoder->Decode(&Asn1Buf, &pRasMessage);
  117. if (dwErrorCode)
  118. {
  119. SPIDER_TRACE(SP_GKI, "PostMessage(m_hWnd, m_wBaseMessage + GKI_ERROR, 0, GKI_DECODER_ERROR)\n", 0);
  120. PostMessage(g_pReg->GetHWnd(), g_pReg->GetBaseMessage() + GKI_ERROR, 0, GKI_DECODER_ERROR);
  121. }
  122. else
  123. {
  124. #ifdef _DEBUG
  125. if (dwGKIDLLFlags & SP_DUMPMEM)
  126. DumpMem(pRasMessage, sizeof(RasMessage));
  127. #endif
  128. hResult = g_pReg->PDUHandler(pRasMessage);
  129. // Notify client app if an error code was received
  130. if (hResult & HR_SEVERITY_MASK)
  131. {
  132. SPIDER_TRACE(SP_GKI, "PostMessage(m_hWnd, m_wBaseMessage + GKI_ERROR, 0, %X)\n", hResult);
  133. PostMessage(g_pReg->GetHWnd(), g_pReg->GetBaseMessage() + GKI_ERROR, 0,
  134. hResult);
  135. }
  136. }
  137. // Free the encoder memory
  138. g_pCoder->Free(pRasMessage);
  139. }
  140. }
  141. //======================================================================================
  142. else
  143. {
  144. // WSAEINTR - returned when socket closed
  145. // get out cleanly
  146. if (g_pReg->m_pSocket->GetLastError() == WSAEINTR)
  147. hResult = GKI_REDISCOVER;
  148. else
  149. {
  150. hResult = GKI_WINSOCK2_ERROR(g_pReg->m_pSocket->GetLastError());
  151. SPIDER_TRACE(SP_GKI, "PostMessage(m_hWnd, m_wBaseMessage + GKI_ERROR, 0, %X)\n", hResult);
  152. PostMessage(g_pReg->GetHWnd(), g_pReg->GetBaseMessage() + GKI_ERROR, 0, hResult);
  153. hResult = GKI_EXIT_THREAD;
  154. }
  155. }
  156. // Release access to the registration object
  157. g_pGatekeeper->Unlock();
  158. }
  159. // Lock access to the registration object
  160. g_pGatekeeper->Lock();
  161. if (g_pReg == 0)
  162. {
  163. SPIDER_TRACE(SP_THREAD, "PostReceive thread exiting\n", 0);
  164. g_pGatekeeper->Unlock();
  165. return;
  166. }
  167. if (hResult != GKI_REDISCOVER)
  168. {
  169. SPIDER_TRACE(SP_NEWDEL, "del g_pReg = %X\n", g_pReg);
  170. delete g_pReg;
  171. g_pReg = 0;
  172. }
  173. else
  174. g_pReg->SetRcvThread(0);
  175. SPIDER_TRACE(SP_THREAD, "PostReceive thread exiting\n", 0);
  176. g_pGatekeeper->Unlock();
  177. }