summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brown2007-01-18 14:26:57 +0100
committerMichael Brown2007-01-18 14:26:57 +0100
commit6c72bf13a1737387f5b1fae9147c49a148855f26 (patch)
tree727d576d9b96769abd3ca39a104f92aab65dd735 /src
parentReorder functions to more closely reflect the flow of control (diff)
downloadipxe-6c72bf13a1737387f5b1fae9147c49a148855f26.tar.gz
ipxe-6c72bf13a1737387f5b1fae9147c49a148855f26.tar.xz
ipxe-6c72bf13a1737387f5b1fae9147c49a148855f26.zip
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).
Diffstat (limited to 'src')
-rw-r--r--src/net/tcp/http.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/net/tcp/http.c b/src/net/tcp/http.c
index 84b8e1664..04e8f9a1d 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 );
};