Browse Source

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).
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
6c72bf13a1
1 changed files with 12 additions and 0 deletions
  1. 12
    0
      src/net/tcp/http.c

+ 12
- 0
src/net/tcp/http.c View File

139
 static int http_rx_content_length ( struct http_request *http,
139
 static int http_rx_content_length ( struct http_request *http,
140
 				    const char *value ) {
140
 				    const char *value ) {
141
 	char *endp;
141
 	char *endp;
142
+	int rc;
142
 
143
 
143
 	http->content_length = strtoul ( value, &endp, 10 );
144
 	http->content_length = strtoul ( value, &endp, 10 );
144
 	if ( *endp != '\0' ) {
145
 	if ( *endp != '\0' ) {
147
 		return -EIO;
148
 		return -EIO;
148
 	}
149
 	}
149
 
150
 
151
+	/* Try to presize the receive buffer */
152
+	if ( ( rc = expand_buffer ( http->buffer,
153
+				    http->content_length ) ) != 0 ) {
154
+		/* May as well abandon the download now; it will fail */
155
+		DBGC ( http, "HTTP %p could not presize buffer: %s\n",
156
+		       http, strerror ( rc ) );
157
+		return rc;
158
+	}
159
+
150
 	return 0;
160
 	return 0;
151
 }
161
 }
152
 
162
 
162
 	 * @v http	HTTP request
172
 	 * @v http	HTTP request
163
 	 * @v value	HTTP header value
173
 	 * @v value	HTTP header value
164
 	 * @ret rc	Return status code
174
 	 * @ret rc	Return status code
175
+	 *
176
+	 * If an error is returned, the download will be aborted.
165
 	 */
177
 	 */
166
 	int ( * rx ) ( struct http_request *http, const char *value );
178
 	int ( * rx ) ( struct http_request *http, const char *value );
167
 };
179
 };

Loading…
Cancel
Save