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

lws_write / large buffer / malloc #529

Closed
pierre-laplante opened this issue May 16, 2016 · 1 comment
Closed

lws_write / large buffer / malloc #529

pierre-laplante opened this issue May 16, 2016 · 1 comment

Comments

@pierre-laplante
Copy link

In the example of the server, you are using malloc to copy the data before using lws_write as in:

...

out = (char )malloc(sizeof(char)(LWS_SEND_BUFFER_PRE_PADDING + len + LWS_SEND_BUFFER_POST_PADDING));
memcpy (out + LWS_SEND_BUFFER_PRE_PADDING, str, len );
n = lws_write(wsi_in, out + LWS_SEND_BUFFER_PRE_PADDING, len, LWS_WRITE_TEXT);

If the buffer is very large, this copy all the data for almost nothing here.

because of that, libwebsocket is very slow. In fact an ajax based solution is twice as fast as websocket.

Is there another way to do this ?

@lws-team
Copy link
Member

It looks like you are pasting from an old version of lws-mirror-protocol, that's the only example code that has this structure.

Using malloc per message, or predefining the ringbuffer is completely the decision of the user code. lws-mirror does it with malloc so it can handle any size message. But if you know the message size limit, you can malloc the ringbuffer at init one time instead perfectly well.

But the ringbuffer itself and the memcpy is needed if you will serve many clients with the same data. Because they will consume it - become writable - each at their own speed.

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