RpcSession.cc 1020 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <boost/bind.hpp>
  2. #include "Rpc/RpcSession.h"
  3. #include "Rpc/RpcServer.h"
  4. namespace Egametang {
  5. RpcSession::RpcSession(boost::asio::io_service& ioService, RpcServer& server):
  6. RpcCommunicator(ioService), rpcServer(server)
  7. {
  8. }
  9. RpcSession::~RpcSession()
  10. {
  11. }
  12. void RpcSession::OnRecvMessage(RpcMetaPtr meta, StringPtr message)
  13. {
  14. RpcSessionPtr session = shared_from_this();
  15. rpcServer.RunService(session, meta, message,
  16. boost::bind(&RpcSession::SendMeta, session, _1, _2));
  17. // 可以循环利用
  18. RecvMeta(meta, message);
  19. }
  20. void RpcSession::OnSendMessage(RpcMetaPtr meta, StringPtr message)
  21. {
  22. }
  23. void RpcSession::Start()
  24. {
  25. RpcMetaPtr meta(new RpcMeta());
  26. StringPtr message(new std::string);
  27. RecvMeta(meta, message);
  28. }
  29. void RpcSession::Stop()
  30. {
  31. RpcSessionPtr session = shared_from_this();
  32. // 延迟删除,必须等所有的bind执行完成后才能remove,
  33. // 否则会出现this指针失效的问题
  34. ioService.post(boost::bind(&RpcServer::Remove, &rpcServer, session));
  35. }
  36. } // namespace Egametang