/TGame/TServerGate/Network/DataHost.h

http://awoe.googlecode.com/ · C Header · 57 lines · 31 code · 13 blank · 13 comment · 0 complexity · b3a8f33627d2c99f419661c0c92e0a3c MD5 · raw file

  1. #ifndef ___DATA_HOST_IMP___
  2. #define ___DATA_HOST_IMP___
  3. #include "DataSessionMgr.h"
  4. //
  5. //
  6. //
  7. //
  8. class DataHost
  9. {
  10. public:
  11. enum
  12. {
  13. num_working_thread = 4,
  14. num_session_mgrs = 2,
  15. };
  16. DataHost();
  17. virtual ~DataHost();
  18. //
  19. // start & stop hosting
  20. //
  21. virtual bool start();
  22. virtual bool stop();
  23. virtual bool wait();
  24. //
  25. // session recycle & reuse
  26. //
  27. virtual bool createSession(DataSession*& pSes);
  28. virtual bool releaseSession(DataSession* pSes);
  29. //
  30. // session start & end
  31. //
  32. virtual void onSessionStart(DataSession* pSes, const boost::system::error_code& error);
  33. virtual void onSessionEnd(DataSession* pSes);
  34. protected:
  35. void post_accept();
  36. protected:
  37. boost::asio::io_service m_theIoSvc;
  38. boost::thread m_theThreads[num_working_thread];
  39. boost::asio::io_service::work m_theEmptyWork;
  40. boost::asio::ip::tcp::endpoint m_theEndPoint;
  41. boost::asio::ip::tcp::acceptor m_theAcceptor;
  42. DataSessionMgr* m_theSesMgrs[num_session_mgrs];
  43. };
  44. #endif