123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #include "protocol.pb.h"
- #include "update_thread.h"
- #include "socket_client.h"
- CUpdateThread::CUpdateThread()
- {
- }
- void CUpdateThread::start(SocketClient* c)
- {
- _client=c;
- _thread=std::thread(&CUpdateThread::run,this);
- }
- void CUpdateThread::run()
- {
- _run=true;
- long long tick = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
- while(_run)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(500));
- if(!_run) break;
- long long diff=std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
- if(diff-tick>3)
- {
- _client->WriteKeepAlive();
- tick=std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
- }
- }
- }
- void CUpdateThread::stop()
- {
- _run=false;
- _thread.join();
- }
- bool CUpdateThread::running()
- {
- return _run;
- }
- CUpdateThread::~CUpdateThread()
- {
- _run = false;
- _thread.join();
- }
|