You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

asynwait.h 784 B

8 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef ASYNWAIT_H
  2. #define ASYNWAIT_H
  3. #include "uniqueid.h"
  4. #include <functional>
  5. #include <list>
  6. #include <mutex>
  7. #include <chrono>
  8. #include <thread>
  9. using namespace std;
  10. using namespace std::chrono;
  11. class AsynWait
  12. {
  13. public:
  14. typedef function<void (IdType)> OnWaitTimeout;
  15. AsynWait();
  16. void start(int precision=200);
  17. void stop();
  18. public:
  19. void addWaitPack(IdType packetId, OnWaitTimeout onTimeout, int msTimeo);
  20. void clearWaitPack(IdType packetId);
  21. private:
  22. void run();
  23. private:
  24. struct WaitPack{
  25. IdType id;
  26. OnWaitTimeout handler;
  27. time_point<system_clock, milliseconds> timeo;
  28. };
  29. list<WaitPack> mWaitPacks;
  30. mutex mPacksMutex;
  31. bool mStarted=false;
  32. int mPrecision;
  33. thread mThd;
  34. };
  35. #endif // ASYNWAIT_H

mac下的“飞秋”大多数只是飞鸽传书协议,而且未发现令人满意的开源项目,所以基于c++与qt实现了基础的飞秋协议。

Contributors (1)