Skip to content

Commit

Permalink
fix http incomplete send handling
Browse files Browse the repository at this point in the history
Signed-off-by: David Gauchard <gauchard@laas.fr>
  • Loading branch information
d-a-v authored and Andy Green committed Jun 29, 2013
1 parent 8294c1f commit 6c58228
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/output.c
Expand Up @@ -504,7 +504,6 @@ LWS_VISIBLE int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf,
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)) {
Expand All @@ -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);
Expand All @@ -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 */
}

/**
Expand Down

0 comments on commit 6c58228

Please sign in to comment.