diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-01-17 01:11:04 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-01-17 01:28:59 +0000 |
commit | 14e0684507c06439ee9c7a731fd6ca90b7b9adcb (patch) | |
tree | ca804fbdee3981c192a527c2102b203ddc82cd94 /http_get.c | |
parent | 37026af96dec638aa850d604003bf7218d90037d (diff) | |
download | cmogstored-14e0684507c06439ee9c7a731fd6ca90b7b9adcb.tar.gz |
This saves several setsockopt() syscalls and reduces system CPU usage.
Diffstat (limited to 'http_get.c')
-rw-r--r-- | http_get.c | 24 |
1 files changed, 12 insertions, 12 deletions
@@ -40,16 +40,16 @@ static ssize_t linux_sendfile(int sockfd, int filefd, off_t *off, size_t count) static off_t http_get_resp_hdr(struct mog_http *http, struct stat *sb) { char *modified; - struct iovec iov; + void *buf; + size_t len; struct mog_now *now = mog_now(); long long count; int rc; - /* single buffer so we can use MSG_MORE later... */ - /* TODO: remove reliance on snprintf(), it eats stack */ - iov.iov_base = mog_fsbuf_get(&iov.iov_len); - modified = (char *)iov.iov_base + iov.iov_len / 2; - assert(iov.iov_len / 2 > MOG_HTTPDATE_CAPA && "fsbuf too small"); + /* single buffer so we can use MSG_MORE */ + buf = mog_fsbuf_get(&len); + modified = (char *)buf + len / 2; + assert((len / 2) > MOG_HTTPDATE_CAPA && "fsbuf too small"); mog_http_date(modified, MOG_HTTPDATE_CAPA, &sb->st_mtime); /* validate ranges */ @@ -101,7 +101,7 @@ static off_t http_get_resp_hdr(struct mog_http *http, struct stat *sb) file->fsize = (off_t)(offset + count); } - rc = snprintf(iov.iov_base, iov.iov_len, + rc = snprintf(buf, len, "HTTP/1.1 206 Partial Content\r\n" "Status: 206 Partial Content\r\n" "Date: %s\r\n" @@ -120,7 +120,7 @@ static off_t http_get_resp_hdr(struct mog_http *http, struct stat *sb) } else { resp_200: count = (long long)sb->st_size; - rc = snprintf(iov.iov_base, iov.iov_len, + rc = snprintf(buf, len, "HTTP/1.1 200 OK\r\n" "Status: 200 OK\r\n" "Date: %s\r\n" @@ -147,7 +147,7 @@ bad_range: assert(http->http_method == MOG_HTTP_METHOD_HEAD && "not HTTP HEAD"); } - rc = snprintf(iov.iov_base, iov.iov_len, + rc = snprintf(buf, len, "HTTP/1.1 " ERR416 "\r\n" "Status: " ERR416 "\r\n" "Date: %s\r\n" @@ -161,11 +161,11 @@ bad_range: http->persistent ? "keep-alive" : "close"); } - assert(rc > 0 && rc < iov.iov_len && "we suck at snprintf"); - iov.iov_len = rc; + assert(rc > 0 && rc < len && "we suck at snprintf"); + len = (size_t)rc; assert(http->wbuf == NULL && "tried to write to a busy client"); - http->wbuf = mog_trywritev(mog_fd_of(http)->fd, &iov, 1); + http->wbuf = mog_trysend(mog_fd_of(http)->fd, buf, len, (off_t)count); return (off_t)count; } |