[wpiutil] WebSocket: Add GetLastReceivedTime

This allows getting the timestamp that any data has been received.
This commit is contained in:
Peter Johnson
2024-01-19 21:25:13 -08:00
parent 77c09b9ce2
commit 9a5366bb83
2 changed files with 9 additions and 0 deletions

View File

@@ -418,6 +418,8 @@ static inline void Unmask(std::span<uint8_t> data,
}
void WebSocket::HandleIncoming(uv::Buffer& buf, size_t size) {
m_lastReceivedTime = m_stream.GetLoopRef().Now().count();
// ignore incoming data if we're failed or closed
if (m_state == FAILED || m_state == CLOSED) {
return;

View File

@@ -457,6 +457,12 @@ class WebSocket : public std::enable_shared_from_this<WebSocket> {
*/
void Shutdown();
/**
* Gets the last time data was received on the stream.
* @return Timestamp
*/
uint64_t GetLastReceivedTime() const { return m_lastReceivedTime; }
/**
* Open event. Emitted when the connection is open and ready to communicate.
* The parameter is the selected subprotocol.
@@ -521,6 +527,7 @@ class WebSocket : public std::enable_shared_from_this<WebSocket> {
State m_state = CONNECTING;
// incoming message buffers/state
uint64_t m_lastReceivedTime = 0;
SmallVector<uint8_t, 14> m_header;
size_t m_headerSize = 0;
SmallVector<uint8_t, 1024> m_payload;