fix http incomplete send handling
authorDavid Gauchard <gauchard@laas.fr>
Sat, 29 Jun 2013 02:24:16 +0000 (10:24 +0800)
committerAndy Green <andy.green@linaro.org>
Sat, 29 Jun 2013 02:24:16 +0000 (10:24 +0800)
Signed-off-by: David Gauchard <gauchard@laas.fr>
lib/output.c

index 37502dd..224a0f2 100644 (file)
@@ -504,7 +504,6 @@ send_raw:
 LWS_VISIBLE int libwebsockets_serve_http_file_fragment(
                struct libwebsocket_context *context, struct libwebsocket *wsi)
 {
-       int ret = 0;
        int n, m;
 
        while (!lws_send_pipe_choked(wsi)) {
@@ -516,7 +515,7 @@ LWS_VISIBLE int libwebsockets_serve_http_file_fragment(
                        if (m < 0)
                                return -1;
 
-                       wsi->u.http.filepos += n;
+                       wsi->u.http.filepos += m;
                        if (m != n)
                                /* adjust for what was not sent */
                                lseek(wsi->u.http.fd, m - n, SEEK_CUR);
@@ -525,23 +524,23 @@ LWS_VISIBLE int libwebsockets_serve_http_file_fragment(
                if (n < 0)
                        return -1; /* caller will close */
 
-               if (n < sizeof(context->service_buffer) ||
-                               wsi->u.http.filepos == wsi->u.http.filelen) {
+               if (wsi->u.http.filepos == wsi->u.http.filelen) {
                        wsi->state = WSI_STATE_HTTP;
 
                        if (wsi->protocol->callback)
-                               ret = user_callback_handle_rxflow(
+                               /* ignore callback returned value */
+                               user_callback_handle_rxflow(
                                        wsi->protocol->callback, context, wsi,
                                        LWS_CALLBACK_HTTP_FILE_COMPLETION,
                                        wsi->user_space, NULL, 0);
-                       return ret;
+                       return 1;  /* >0 indicates completed */
                }
        }
 
        lwsl_notice("choked before able to send whole file (post)\n");
        libwebsocket_callback_on_writable(context, wsi);
 
-       return ret;
+       return 0; /* indicates further processing must be done */
 }
 
 /**