-
Notifications
You must be signed in to change notification settings - Fork 88
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
Problem with recent change to the calling sequence for the function 'ws_socket() #86
Comments
Hi @grm1209, What must be happening in your case is that the function returns even before this thread is created, and thus the structure is no longer valid. This is a bug and needs to be fixed. I will address it as soon as possible. Thank you for bringing it to my attention. |
In PR #82, the signature of the ws_socket() function was modified to receive a 'ws_server' structure as a parameter. However, the content of this structure was only copied later when the thread for performing accepts() was created. This could lead to a situation where, if the 'ws_server' structure was allocated on the stack, a potential function return (prior to thread execution) would render the address invalid, effectively creating a race condition between thread creation and function return. The fix is straightforward: simply have the 'ws_accept_params' structure store the 'ws_server' structure itself instead of a pointer to it. This should address issue #86.
library has problem with socket accepting connection , can you help i am stuck here for two days |
Hi @Vaibhav-singh78, Anyway, could you provide more details? your operating system? code used etc? An 'MRE' (Minimal, Reproducible Example) would be very useful to better understand your problem. |
The recent change to the calling sequence for the function 'ws_socket(struct ws_server *ws_srv)' causes problems if the 'ws_server' structure is in the stack of the calling function and the function exits after calling a non-blocking 'ws_socket()'.
Previously, the callers 'ws_events' structure was copied the wsServer's 'ws_server' structure. Now, the caller's pointer to it's 'ws_server' structure is placed in the wsServer's 'ws_accept_params' structure.
When the calling function exits, it's 'ws_server' structure becomes undefined. The solution for the caller is to allocate the 'ws_server' structure in local space.
A note of this should be included in the documentation. And maybe the examples like 'echo' should do this instead of using stack allocation.
My environment:
The text was updated successfully, but these errors were encountered: