Skip to content
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

It's illegal to do an lws_write outside of the writable callback error #852

Closed
eduard739 opened this issue Mar 29, 2017 · 4 comments
Closed

Comments

@eduard739
Copy link

I'm getting "It's illegal to do an lws_write outside of the writable callback: fix your code" error
but the only place i use lws_write in inside the LWS_CALLBACK_CLIENT_WRITEABLE case. am i doing something wrong or is it a bug?

@lws-team
Copy link
Member

The warning is actually coming because you tried to do an lws_write() while another one was only partially sent.

The usual way that's happening is people just doing lws_write() randomly.

However two or more lws_write() inside the writable callback can also cause it, if the first one was unable to send everything.

So you should marshall what you want to write into a buffer and write it once (on lws_write() call) per writable callback.

@eduard739
Copy link
Author

even if i use while(lws_partial_buffered(wsi) != 1){/* send here */}?

@lws-team
Copy link
Member

Just doing that will protect you against colliding with a pending partial write.

But only the first one is guaranteed to be writing when the socket has signalled POLLOUT, ie the attempt to write is related to the state of the network connection.

lws_send_pipe_choked(wsi) is better since it checks both pending partial and writability and returns nonzero on either. But if you will handle multiple simultaneous connections it's best to just do one write, ask for the writable callback, and return to the event loop.

@lws-team
Copy link
Member

I assume the original problem is solved by one or other of the methods discussed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants