[performance] use scatter/gather for htp__create_headers_
@@ -2017,12 +2017,21 @@ static int
htp__create_headers_(evhtp_header_t * header, void * arg)
{
struct evbuffer * buf = arg;
+ struct evbuffer_iovec iov[4];
- evbuffer_expand(buf, header->klen + 2 + header->vlen + 2);
- evbuffer_add(buf, header->key, header->klen);
- evbuffer_add(buf, ": ", 2);
- evbuffer_add(buf, header->val, header->vlen);
- evbuffer_add(buf, "\r\n", 2);
+ iov[0].iov_base = header->key;
+ iov[0].iov_len = header->klen;
+
+ iov[1].iov_base = ": ";
+ iov[1].iov_len = 2;
+
+ iov[2].iov_base = header->val;
+ iov[2].iov_len = header->vlen;
+
+ iov[3].iov_base = "\r\n";
+ iov[3].iov_len = 2;
+
+ evbuffer_add_iovec(buf, iov, 4);
return 0;
}
@@ -2134,31 +2143,40 @@ check_proto:
struct evbuffer_iovec iov[9];
const char * status_str = status_code_to_str(code);
+ /* data == "HTTP/" */
iov[0].iov_base = "HTTP/";
iov[0].iov_len = 5;
+ /* data == "HTTP/X" */
iov[1].iov_base = (void *)&major;
iov[1].iov_len = 1;
+ /* data == "HTTP/X." */
iov[2].iov_base = ".";
iov[2].iov_len = 1;
+ /* data == "HTTP/X.X" */
iov[3].iov_base = (void *)&minor;
iov[3].iov_len = 1;
+ /* data == "HTTP/X.X " */
iov[4].iov_base = " ";
iov[4].iov_len = 1;
+ /* data == "HTTP/X.X YYY" */
iov[5].iov_base = out_buf;
iov[5].iov_len = strlen(out_buf);
+ /* data == "HTTP/X.X YYY " */
iov[6].iov_base = " ";
iov[6].iov_len = 1;
+ /* data == "HTTP/X.X YYY ZZZ" */
iov[7].iov_base = (void *)status_str;
iov[7].iov_len = strlen(status_str);
+ /* data == "HTTP/X.X YYY ZZZ\r\n" */
iov[8].iov_base = "\r\n";
iov[8].iov_len = 2;
