GameServerWorkerThread.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:2k
源码类别:

模拟服务器

开发平台:

C/C++

  1. #include "GameServerWorkerThread.h"
  2. //[ Include in ...IPCPServer
  3. #include "IOCPServerUtils.h"
  4. #include "IOCPServertstring.h"
  5. #include "IOCPServerException.h"
  6. //]
  7. #include "JXServer.h"
  8. #pragma comment (lib, "IOCPServer.lib")
  9. /*
  10.  * Using directives
  11.  */
  12. using OnlineGameLib::Win32::CIOCompletionPort;
  13. using OnlineGameLib::Win32::CIOBuffer;
  14. using OnlineGameLib::Win32::CSocketServer;
  15. using OnlineGameLib::Win32::Output;
  16. using OnlineGameLib::Win32::OutPutInfo;
  17. using OnlineGameLib::Win32::_tstring;
  18. using OnlineGameLib::Win32::CException;
  19. using OnlineGameLib::Win32::ToString;
  20. using OnlineGameLib::Win32::DumpData;
  21. CGameServerWorkerThread::CGameServerWorkerThread(
  22.  CIOCompletionPort &iocp)
  23.    : CSocketServer::WorkerThread(iocp)
  24. {
  25. }
  26. CGameServerWorkerThread::~CGameServerWorkerThread()
  27. {
  28. }
  29. void CGameServerWorkerThread::OnBeginProcessing()
  30. {
  31. // Output( _T("OnBeginProcessing") );
  32. }
  33. void CGameServerWorkerThread::ReadCompleted(
  34. CSocketServer::Socket *pSocket,
  35. CIOBuffer *pBuffer)
  36. {
  37. try
  38. {
  39. unsigned long ulnID = pSocket->GetUserData();
  40. const BYTE *pPackData = pBuffer->GetBuffer();
  41. const size_t used = pBuffer->GetUsed();
  42. RecvFromClient( ulnID, reinterpret_cast<const char*>( pPackData ), used );
  43. pBuffer->Empty();
  44. pSocket->Read( pBuffer );
  45. }
  46. catch(const CException &e)
  47. {
  48. Output( _T("ReadCompleted - Exception - ") + e.GetWhere() + _T(" - ") + e.GetMessage() );
  49. pSocket->Shutdown();
  50. }
  51. catch(...)
  52. {
  53. Output( _T("ReadCompleted - Unexpected exception") );
  54. pSocket->Shutdown();
  55. }
  56. }
  57. void CGameServerWorkerThread::OnEndProcessing()
  58. {
  59. // Output( _T("OnEndProcessing") );
  60. }
  61. void CGameServerWorkerThread::OnError( const OnlineGameLib::Win32::_tstring &message )
  62. {
  63. Output( _T("OnError - ") + message );
  64. }