Use mono time for event arrival time

This commit is contained in:
Benau 2019-05-12 14:33:48 +08:00
parent d7bffa4ade
commit b0695b08a5
4 changed files with 5 additions and 6 deletions

View File

@ -41,7 +41,7 @@ constexpr bool isConnectionRequestPacket(unsigned char* data, size_t length)
// ============================================================================
Event::Event(ENetEvent* event, std::shared_ptr<STKPeer> peer)
{
m_arrival_time = (double)StkTime::getTimeSinceEpoch();
m_arrival_time = StkTime::getMonoTimeMs();
m_pdi = PDI_TIMEOUT;
m_peer = peer;

View File

@ -84,7 +84,7 @@ private:
std::shared_ptr<STKPeer> m_peer;
/** Arrivial time of the event, for timeouts. */
double m_arrival_time;
uint64_t m_arrival_time;
/** For disconnection event, a bit more info is provided. */
PeerDisconnectInfo m_pdi;
@ -119,7 +119,7 @@ public:
m_data->isSynchronous(); }
// ------------------------------------------------------------------------
/** Returns the arrival time of this event. */
double getArrivalTime() const { return m_arrival_time; }
uint64_t getArrivalTime() const { return m_arrival_time; }
// ------------------------------------------------------------------------
PeerDisconnectInfo getPeerDisconnectInfo() const { return m_pdi; }
// ------------------------------------------------------------------------

View File

@ -449,7 +449,8 @@ bool ProtocolManager::sendEvent(Event* event)
can_be_deleted |= m_all_protocols.at(i).notifyEvent(event);
}
}
return can_be_deleted || StkTime::getTimeSinceEpoch() - event->getArrivalTime()
const uint64_t TIME_TO_KEEP_EVENTS = 1000;
return can_be_deleted || StkTime::getMonoTimeMs() - event->getArrivalTime()
>= TIME_TO_KEEP_EVENTS;
} // sendEvent

View File

@ -41,8 +41,6 @@
class Event;
class STKPeer;
#define TIME_TO_KEEP_EVENTS 1.0
// ----------------------------------------------------------------------------
/** \enum ProtocolRequestType
* \brief Defines actions that can be done about protocols.