-
Notifications
You must be signed in to change notification settings - Fork 92
Made it possible to set client context for the listening server too. #93
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
Conversation
Hi @dkorolev, I expected the context pointer to be inside |
Got it. Sleeping over it again! |
Honestly, maybe we can keep the two approaches, one with a global pointer (like the one in this PR, saving it in |
Looks like the cleanest minimum-delta solution is to have two contexts: the The The Thought experiment: each websocket connection should know its unique autoincremented ID. The variable with the next ID (as well as the mutex guarding it, unless it's an We could call it the If you think this is a workable idea, I'd be happy to put it into code. |
Yes, completely agree, something like this is more than enough for me: ws_socket(&(struct ws_server){
.host = "localhost",
.port = 8080,
.thread_loop = 0,
.timeout_ms = 1000,
.evs.onopen = &onopen,
.evs.onclose = &onclose,
.evs.onmessage = &onmessage,
.context = my_pointer // <<<-- here
}); Since
Yes, this partially happens in the last PR (#91), but here saving the context into
I think I understand the idea, but not the objective. I think it is important to keep the server code simple and I don't know if having a connection id would bring any direct benefit. For me, the ideas of pointers in the server context and connection/client context have a clear benefit, but this last idea not so much. |
Ah, I only meant the incrementing indexes as an example -- and added it too in a separate commit: 5bd34ec This PR now separates the server context from per-connection contexts. Per-connection contexts are called connection contexts, and the term |
Hi @dkorolev Although targeted for C users, I don't want to introduce/force concepts like threads, mutexes and etc, let alone for the first/simplest example file. Please undo your changes in |
5bd34ec
to
075cefe
Compare
Most certainly. The second commit with an example was mostly a sanity check, plus perhaps to make the code review more enjoyable. Agree the code in the repo looks just fine with Removed this second commit from the PR, leaving only the change with the context. For future readers of this thread, the now-removed change to Please take another look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @dkorolev,
Thank you very much for the persistence while considering my suggestions, it is now the way I've envisioned =).
Approved.
Pleasure working with you on this one! |
Hi @dkorolev,
Just a heads up that this was added in #96. I apologize for not fully understanding the advantages of an ID/UID/Connection ID, but as already discussed in issue #66 (from a year ago, and which I didn't remember), having an ID solves many problems, mainly regarding the lifetime of 'ws_cli_conn_t' and also regarding the certainty of whether a message was actually delivered to the client or not, an issue that had been around for a long time. |
Hi @Theldus,
Slept over what we introduced in #91 yesterday.
Yes, it will have to be the client's responsibility to be mindful that the client context pointer will persist across connections. The clients for whom this matters should use the
onclose
handler then.Also, I realized it can be needed to set the client context before the connection is established, just as the server begins listening. And here is the PR.
The issue ID remains the same, #48.
Thanks,
Dima