[Libwebsockets] Serving a large file using LWSMPRO_CALLBACK vhost

Andy Green andy at warmcat.com
Tue Jan 14 20:24:59 CET 2020

On 1/14/20 5:34 PM, Thomas Spitz wrote:
> Hello,
> I would like to send a large file from a vhost whose origin_protocol is 
> LWSMPRO_CALLBACK. I cannot use origin_protocol LWSMPRO_FILE because the 
> URI path and the file location are very different.

If it's just one or two physical files, it  might be possible to use the 
redirect mount types (or symlinks in the file system) to make the names 
line up.

> I manage to do so using lws_serve_http_file() from LWS_CALLBACK_HTTP but 
> this blocks the server until the file is served (websockets clients are 
> not updated until the end of the sending). In order to avoid such 

That's surprising since that's the internal api that's used for sending 
files, and that definitely doesn't block anything.

> blockage, I suppose a good design is to send the file by chunk through 
> LWS_CALLBACK_HTTP_WRITEABLE in the same principle as in 
> minimal-http-server-dynamic?


> Assuming I am right, I got back to test-server-http.c (libwesockets 
> <2.4) where the leaf.jpg was send "by hand" using 
> LWS_CALLBACK_HTTP_WRITEABLE and lws_plat_file functions but It seems 
> that those lws_plat_file functions are not available anymore in lws 
> newest versions. Is it something wanted?

That stuff got replaced by vfs apis


but there is no need to use it, you can open the file using normal POSIX 
apis if that's what you want.


> Thank in advance
> Thomas
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets

More information about the Libwebsockets mailing list