david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

Presize the download buffer when we see the Content-Length header;

this saves around 70us per received packet (which is around 50% of the
overall packet processing time).
This commit is contained in:
Michael Brown 2007-01-18 13:26:57 +00:00
parent 08da93a311
commit 6c72bf13a1
1 changed files with 12 additions and 0 deletions

View File

@ -139,6 +139,7 @@ static void http_rx_response ( struct http_request *http, char *response ) {
static int http_rx_content_length ( struct http_request *http,
const char *value ) {
char *endp;
int rc;
http->content_length = strtoul ( value, &endp, 10 );
if ( *endp != '\0' ) {
@ -147,6 +148,15 @@ static int http_rx_content_length ( struct http_request *http,
return -EIO;
}
/* Try to presize the receive buffer */
if ( ( rc = expand_buffer ( http->buffer,
http->content_length ) ) != 0 ) {
/* May as well abandon the download now; it will fail */
DBGC ( http, "HTTP %p could not presize buffer: %s\n",
http, strerror ( rc ) );
return rc;
}
return 0;
}
@ -162,6 +172,8 @@ struct http_header_handler {
* @v http HTTP request
* @v value HTTP header value
* @ret rc Return status code
*
* If an error is returned, the download will be aborted.
*/
int ( * rx ) ( struct http_request *http, const char *value );
};