-
-
Notifications
You must be signed in to change notification settings - Fork 345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebSocketConnection: make getActiveWebSockets() static #1469
Conversation
What is the use-case for directly using |
Consider the following scenario:
At (7) we need to validate the websocket to (a) ensure it's still valid, and (b) hasn't been reassigned to another client. My solution to this is was to assign a unique CID to the WebSocketConnection (actually an inherited class) at (1), then searching the active websockets list for a matching CID at (7). It uses getActiveWebsockets() do to this. Note that CID cannot be the WebSocketConnection object address. I'll have a PR for this at some point... |
In this specific case, it is about the distribution of messages to all clients that have subscribed to a specific message types (publish-subscribe pattern). Broadcast can't be used because only subscribing clients should receive the specific messages. There is no specific object reference in the context of the event that triggers the message generation. The subscription information is stored very efficiently with setUserData(). Managing a separate lists of subscribing clients would be possible, but less efficient. |
@tuis2000 One of my changes is to provide a createConnection() callback in WebsocketResource to allow WebSocketConnection to be overridden. That should make your scenario even easier to implement. |
@tius2000 If you want this PR merged in this release, please, rebase it on the latest |
@mikee47 Do you want to submit your PR related to websockets? There are no major changes in the pipeline from me related to websockets. |
…tatic`, returning `const WebsocketList` to prevent dangerous modifications. See SmingHub#1469
I've mulled this over and I think my suggestion of overriding |
Sounds good. Send a PR with the proposed changes. Meanwhile I am closing this PR. |
…tatic`, returning `const WebsocketList` to prevent dangerous modifications. See SmingHub#1469
…tatic`, returning `const WebsocketList` to prevent dangerous modifications. See SmingHub#1469
* Fix memory leaks in `HttpConnection` Change `waitingQueue` from un-owned `RequestQueue*` to `RequestQueue` Free request if queue is full in `send(HttpRequest*)` * Tidy up * Code out of header * Merge `HttpClientConnection` into `HttpConnection` * HttpConnection -> HttpClientConnection * HttpConnectionBase -> HttpConnection * Move `isActive()` from `HttpClientConnection` into `HttpConnection` - applicable to both server and client * Resolve `HttpClientConnection` methods temporarily un-deprecated in #1629 * Revise `HttpConnection` so it can be used with either client or server Move `response` member variable into `HttpConnection` as both client and server have this. Move `getResponse()` method from `HttpClientConnection` into `HttpConnection` Add virtual `getRequest()` method to HttpConnection Move applicable methods from `HttpClientConnection` into `HttpConnection` Note: `send(HttpRquest*)` made virtual in previous commit * Fix comments * Fix deprecated method calls * Don't initialise `userData` in `WebsocketConnection` constructor * Un-deprecate `WebsocketConnection::getActiveWebsockets()` and make `static`, returning `const WebsocketList` to prevent dangerous modifications. See #1469
IMHO getActiveWebSockets() should be declared static. This it allows it to be used with and without an object reference.
BTW: It is marked deprecated, what method should be used instead?