Message.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "servant/Message.h"
  2. #include "servant/ServantProxy.h"
  3. #include "servant/Communicator.h"
  4. namespace tars
  5. {
  6. void ReqMessage::init(CallType eCallType, ServantProxy *prx)
  7. {
  8. eStatus = ReqMessage::REQ_REQ;
  9. eType = eCallType;
  10. bFromRpc = false;
  11. callback = NULL;
  12. proxy = prx;
  13. pObjectProxy = NULL;
  14. request.iRequestId = 1;
  15. response = std::make_shared<ResponsePacket>();
  16. sReqData = std::make_shared<TC_NetWorkBuffer::Buffer>();
  17. pMonitor = NULL;
  18. iBeginTime = TNOWMS;
  19. iEndTime = 0;
  20. adapter = NULL;
  21. bPush = false;
  22. sched = NULL;
  23. iCoroId = 0;
  24. }
  25. ReqMessage::~ReqMessage()
  26. {
  27. if(deconstructor)
  28. {
  29. deconstructor();
  30. }
  31. if(pMonitor != NULL)
  32. {
  33. delete pMonitor;
  34. pMonitor = NULL;
  35. }
  36. }
  37. /////////////////////////////////////////////////////////////////////////////
  38. void ReqMonitor::wait()
  39. {
  40. if(!bMonitorFin)
  41. {
  42. std::unique_lock<std::mutex> lock(mutex);
  43. if (!bMonitorFin)
  44. {
  45. cond.wait(lock, [&]
  46. { return bMonitorFin || msg->proxy->tars_communicator()->isTerminating(); });
  47. }
  48. }
  49. }
  50. void ReqMonitor::notify()
  51. {
  52. std::unique_lock<std::mutex> lock(mutex);
  53. bMonitorFin = true;
  54. cond.notify_one();
  55. }
  56. }