[Libwebsockets] Error When Serving Large Files via HTTP

Chad Cravens chad.cravens at ossys.com
Tue Dec 16 03:18:54 CET 2014


When attempting to serve large files (~ >500K) using the
libwebsockets_serve_http_file() method, most of the time the call will hang
causing chrome to issue a ERR_CONTENT_LENGTH_MISMATCH error.

This happens most of the time, but about every 8-10 browser refreshes the
entire file is served without a problem. I noticed that this same error
occurs in the example application libwebsockets-test-server that is built
when compiling libwebsockets from source on my MacOSX.

The following is the code I am using to serve the file:

Log::instance()->logDebug("SERVING HTTP FILE: " + resource);
ret = libwebsockets_serve_http_file(context, wsi, resource.c_str(),
mime.c_str(), "");
Log::instance()->logDebug("SERVED HTTP FILE: " + resource);

I also put debug statements for every callback made. I noticed that when
properly serving large files the debug output looks like the following:

[LOG_DEBUG] SERVING HTTP FILE: deps.js
LWS_CALLBACK_HTTP_FILE_COMPLETION
[LOG_DEBUG] SERVED HTTP FILE: deps.js
RESULT OF HTTP: 1

However, when there is an error serving the file as stated above, the
callback output looks like the following:
[LOG_DEBUG] SERVING HTTP FILE: deps.js
LWS_CALLBACK_LOCK_POLL
LWS_CALLBACK_CHANGE_MODE_POLL_FD
LWS_CALLBACK_UNLOCK_POLL
LWS_CALLBACK_LOCK_POLL
LWS_CALLBACK_CHANGE_MODE_POLL_FD
LWS_CALLBACK_UNLOCK_POLL
[LOG_DEBUG] SERVED HTTP FILE: deps.js
LWS_CALLBACK_LOCK_POLL
LWS_CALLBACK_CHANGE_MODE_POLL_FD
LWS_CALLBACK_UNLOCK_POLL
RESULT OF HTTP: 0

When there is an error there additional callbacks that are called an
apparently I am not handling the buffering properly. For a while I have
been trying to work the issue and figure out how to properly handle
buffering and serving large files via HTTP.

Any guidance in my approach or examples / documentation would be GREATLY
appreciated!!

Kindest Regards,
Chad

-- 
[image: http://www.ossys.com] <http://www.ossys.com>
[image: http://www.linkedin.com/company/open-source-systems-llc]
<http://www.linkedin.com/company/open-source-systems-llc>   [image:
https://www.facebook.com/OpenSrcSys] <https://www.facebook.com/OpenSrcSys>
   [image: https://twitter.com/OpenSrcSys] <https://twitter.com/OpenSrcSys>
     [image: http://www.youtube.com/OpenSrcSys]
<http://www.youtube.com/OpenSrcSys>   [image: http://www.ossys.com/feed]
<http://www.ossys.com/feed>   [image: contact at ossys.com] <contact at ossys.com>
Chad Cravens
(843) 291-8340
chad.cravens at ossys.com
http://www.ossys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://libwebsockets.org/pipermail/libwebsockets/attachments/20141215/1248603f/attachment.html>


More information about the Libwebsockets mailing list