aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/webcore/WebSocket.h
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-10 17:40:17 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-10 17:40:17 -0700
commitf09e7ac6306726578b5200b7651c2660e093802c (patch)
treeb92d157e8d3f249d30e96f2aaf666e031f38ec6b /src/bun.js/bindings/webcore/WebSocket.h
parente511b14b2ab08d86dc9c15d41b3c5da2f7d8b751 (diff)
downloadbun-f09e7ac6306726578b5200b7651c2660e093802c.tar.gz
bun-f09e7ac6306726578b5200b7651c2660e093802c.tar.zst
bun-f09e7ac6306726578b5200b7651c2660e093802c.zip
improve reliability of `WebSocket`
- Fix GC not keeping WebSocket alive - Fix ignoring messages sent immediately after upgrade Fixes https://github.com/oven-sh/bun/issues/521
Diffstat (limited to 'src/bun.js/bindings/webcore/WebSocket.h')
-rw-r--r--src/bun.js/bindings/webcore/WebSocket.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/bun.js/bindings/webcore/WebSocket.h b/src/bun.js/bindings/webcore/WebSocket.h
index 03c0d7709..7fd4e24a7 100644
--- a/src/bun.js/bindings/webcore/WebSocket.h
+++ b/src/bun.js/bindings/webcore/WebSocket.h
@@ -103,6 +103,11 @@ public:
void didReceiveData(const char* data, size_t length);
void didReceiveBinaryData(Vector<uint8_t>&&);
+ bool hasPendingActivity() const
+ {
+ return m_state == State::OPEN || m_state == State::CLOSING || m_pendingActivityCount > 0;
+ }
+
private:
typedef union AnyWebSocket {
WebSocketClient* client;
@@ -157,6 +162,7 @@ private:
bool m_isSecure { false };
AnyWebSocket m_connectedWebSocket { nullptr };
ConnectedWebSocketKind m_connectedWebSocketKind { ConnectedWebSocketKind::None };
+ size_t m_pendingActivityCount { 0 };
bool m_dispatchedErrorEvent { false };
// RefPtr<PendingActivity<WebSocket>> m_pendingActivity;