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:
parent
08da93a311
commit
6c72bf13a1
@ -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,
|
static int http_rx_content_length ( struct http_request *http,
|
||||||
const char *value ) {
|
const char *value ) {
|
||||||
char *endp;
|
char *endp;
|
||||||
|
int rc;
|
||||||
|
|
||||||
http->content_length = strtoul ( value, &endp, 10 );
|
http->content_length = strtoul ( value, &endp, 10 );
|
||||||
if ( *endp != '\0' ) {
|
if ( *endp != '\0' ) {
|
||||||
@ -147,6 +148,15 @@ static int http_rx_content_length ( struct http_request *http,
|
|||||||
return -EIO;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,6 +172,8 @@ struct http_header_handler {
|
|||||||
* @v http HTTP request
|
* @v http HTTP request
|
||||||
* @v value HTTP header value
|
* @v value HTTP header value
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
|
*
|
||||||
|
* If an error is returned, the download will be aborted.
|
||||||
*/
|
*/
|
||||||
int ( * rx ) ( struct http_request *http, const char *value );
|
int ( * rx ) ( struct http_request *http, const char *value );
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user