SocketRx.cpp
上传用户:aphszp
上传日期:2007-01-09
资源大小:42k
文件大小:1k
源码类别:

Telnet服务器

开发平台:

Visual C++

  1. // SocketRx.cpp: implementation of the CSocketRx class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Telnet.h"
  6. #include "ProtocolRx.h"
  7. #include "SocketRx.h"
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char THIS_FILE[]=__FILE__;
  11. #define new DEBUG_NEW
  12. #endif
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. CSocketRx::CSocketRx()
  17. {
  18. }
  19. CSocketRx::CSocketRx(SOCKET hSocket,HANDLE &hThread)
  20. {
  21. DWORD dwRet;
  22. m_nExit = 0;
  23. m_hThread = NULL;
  24. m_hSocket = hSocket;
  25. m_hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE) RdTh,(LPVOID)this,0,&dwRet);
  26. if ( m_hThread == NULL ) return;
  27. hThread = m_hThread;
  28. }
  29. CSocketRx::~CSocketRx()
  30. {
  31. m_nExit = 1;
  32. }
  33. DWORD CSocketRx::RdTh(CSocketRx *pSocketRx)
  34. {
  35. char pBuf[256];
  36. char* scan;
  37. int nRet;
  38.   while(1)
  39.   {
  40. if ( pSocketRx->m_nExit == 1 ) { ExitThread(0); return 0; }
  41.     nRet = recv(pSocketRx->m_hSocket,pBuf,sizeof(pBuf),0);
  42. if ( nRet == SOCKET_ERROR ) { TRACE( "nRaed Fail.........!n" ); pSocketRx->m_nExit = 1; continue;}
  43. if ( nRet == 0) Sleep(10);
  44. scan = pBuf;
  45. while(nRet--)
  46. {
  47. pSocketRx->m_Protocol.TelentProtcol(pSocketRx->m_hSocket,*scan++);
  48. TRACE("%c ",*scan);
  49. }
  50.   }
  51.   return 0;
  52. }