mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpiutil] WebSocket: Add GetLastReceivedTime
This allows getting the timestamp that any data has been received.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user