Correctly deal with write errors when delivering files over HTTP

This commit is contained in:
Andreas Öman 2011-05-04 14:16:32 +02:00
parent 982802181c
commit b197beb3e3
2 changed files with 9 additions and 7 deletions

View file

@ -333,7 +333,7 @@ http_access_verify(http_connection_t *hc, int mask)
* Returns 1 if we should disconnect
*
*/
static void
static int
http_exec(http_connection_t *hc, http_path_t *hp, char *remain)
{
int err;
@ -343,8 +343,12 @@ http_exec(http_connection_t *hc, http_path_t *hp, char *remain)
else
err = hp->hp_callback(hc, remain, hp->hp_opaque);
if(err == -1)
return 1;
if(err)
http_error(hc, err);
return 0;
}
@ -368,8 +372,7 @@ http_cmd_get(http_connection_t *hc)
if(args != NULL)
http_parse_get_args(hc, args);
http_exec(hc, hp, remain);
return 0;
return http_exec(hc, hp, remain);
}
@ -431,8 +434,7 @@ http_cmd_post(http_connection_t *hc, htsbuf_queue_t *spill)
http_error(hc, HTTP_STATUS_NOT_FOUND);
return 0;
}
http_exec(hc, hp, remain);
return 0;
return http_exec(hc, hp, remain);
}

View file

@ -487,7 +487,6 @@ page_static_bundle(http_connection_t *hc, const char *remain, void *opaque)
const struct filebundle *fb = opaque;
const struct filebundle_entry *fbe;
const char *content = NULL, *postfix;
int n;
if(remain == NULL)
return 404;
@ -506,7 +505,8 @@ page_static_bundle(http_connection_t *hc, const char *remain, void *opaque)
fbe->original_size == -1 ? NULL : "gzip", NULL, 10, 0,
NULL);
/* ignore return value */
n = write(hc->hc_fd, fbe->data, fbe->size);
if(write(hc->hc_fd, fbe->data, fbe->size) != fbe->size)
return -1;
return 0;
}
}