From 6c72bf13a1737387f5b1fae9147c49a148855f26 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 18 Jan 2007 13:26:57 +0000 Subject: [PATCH] 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). --- src/net/tcp/http.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/net/tcp/http.c b/src/net/tcp/http.c index 84b8e166..04e8f9a1 100644 --- a/src/net/tcp/http.c +++ b/src/net/tcp/http.c @@ -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 ); };