PushImp.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "PushImp.h"
  2. #include "servant/Application.h"
  3. #include "PushThread.h"
  4. using namespace std;
  5. //////////////////////////////////////////////////////
  6. void PushImp::initialize()
  7. {
  8. //initialize servant here:
  9. //...
  10. }
  11. //////////////////////////////////////////////////////
  12. void PushImp::destroy()
  13. {
  14. //destroy servant here:
  15. //...
  16. }
  17. int PushImp::doRequest(tars::CurrentPtr current, vector<char>& response)
  18. {
  19. // LOG_CONSOLE_DEBUG << endl;
  20. //保存客户端的信息,以便对客户端进行push消息
  21. (PushUser::mapMutex).lock();
  22. map<string, CurrentPtr>::iterator it = PushUser::pushUser.find(current->getIp());
  23. if(it == PushUser::pushUser.end())
  24. {
  25. PushUser::pushUser.insert(map<string, CurrentPtr>::value_type(current->getIp(), current));
  26. LOG->debug() << "connect ip: " << current->getIp() << endl;
  27. }
  28. (PushUser::mapMutex).unlock();
  29. //返回给客户端它自己请求的数据包,即原包返回(4字节长度+4字节requestid+buffer)
  30. const vector<char>& request = current->getRequestBuffer();
  31. response = request;
  32. return 0;
  33. }
  34. //客户端关闭到服务端的连接,或者服务端发现客户端长时间未发送包过来,然后超过60s就关闭连接
  35. //调用的方法
  36. int PushImp::doClose(CurrentPtr current)
  37. {
  38. (PushUser::mapMutex).lock();
  39. map<string, CurrentPtr>::iterator it = PushUser::pushUser.find(current->getIp());
  40. if(it != PushUser::pushUser.end())
  41. {
  42. PushUser::pushUser.erase(it);
  43. LOG->debug() << "close ip: " << current->getIp() << endl;
  44. }
  45. (PushUser::mapMutex).unlock();
  46. return 0;
  47. }