Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
cleanup / optimization for iovec operations
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFrench committed Jan 30, 2019
1 parent 718c406 commit 874a225
Showing 1 changed file with 18 additions and 52 deletions.
70 changes: 18 additions & 52 deletions evhtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2044,20 +2044,13 @@ htp__evbuffer_add_iovec_(struct evbuffer * buf, struct evbuffer_iovec * vec, int
static int
htp__create_headers_(evhtp_header_t * header, void * arg)
{
struct evbuffer * buf = arg;
struct evbuffer_iovec iov[4];

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;
struct evbuffer * buf = arg;
struct evbuffer_iovec iov[4] = {
{ header->key, header->klen },
{ ": ", 2 },
{ header->val, header->vlen },
{ "\r\n", 2 }
};

htp__evbuffer_add_iovec_(buf, iov, 4);

Expand Down Expand Up @@ -2168,45 +2161,18 @@ htp__create_reply_(evhtp_request_t * request, evhtp_res code)
* of the header.
*/
{
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;
struct evbuffer_iovec iov[9] = {
{ "HTTP/1", 5 }, /* data == "HTTP/" */
{ (void *)&major, 1 }, /* data == "HTTP/X */
{ ".", 1 }, /* data == "HTTP/X." */
{ (void *)&minor, 1 }, /* data == "HTTP/X.X" */
{ " ", 1 }, /* data == "HTTP/X.X " */
{ out_buf, strlen(out_buf) }, /* data = "HTTP/X.X YYY" */
{ " ", 1 }, /* data = "HTTP/X.X YYY " */
{ (void *)status_str, strlen(status_str) }, /* data = "HTTP/X.X YYY ZZZ" */
{ "\r\n", 2 }, /* data = "HTTP/X.X YYY ZZZ\r\n" */
};

htp__evbuffer_add_iovec_(buf, iov, 9);
}
Expand Down

0 comments on commit 874a225

Please sign in to comment.