From 74af25e5db8233248ba8a2533f1cd2174a52f711 Mon Sep 17 00:00:00 2001 From: Robert Watson Date: Thu, 6 Oct 2005 10:28:31 +0000 Subject: [PATCH] Improve realism of benchmark httpd: return some HTTP headers as part of the sendfile() system call. --- tools/tools/netrate/httpd/httpd.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tools/tools/netrate/httpd/httpd.c b/tools/tools/netrate/httpd/httpd.c index d8907ffdc7bb..549fe4a8bff5 100644 --- a/tools/tools/netrate/httpd/httpd.c +++ b/tools/tools/netrate/httpd/httpd.c @@ -28,6 +28,7 @@ #include #include +#include #include @@ -48,6 +49,11 @@ #define BUFFER (48*1024) #define HTTP 8000 +#define HTTP_OK "HTTP/1.1 200 OK\n" +#define HTTP_SERVER "Server rwatson_httpd/1.0 (FreeBSD)\n" +#define HTTP_CONNECTION "Connection: close\n" +#define HTTP_CONTENT "Content-Type: text/html\n" + static const char *path; static int listen_sock; static int data_file; @@ -58,6 +64,8 @@ static int data_file; static int http_serve(int sock) { + struct iovec header_iovec[4]; + struct sf_hdtr sf_hdtr; ssize_t len; int ncount; char ch; @@ -78,7 +86,22 @@ http_serve(int sock) break; } - if (sendfile(data_file, sock, 0, 0, NULL, NULL, 0) < 0) + bzero(&sf_hdtr, sizeof(sf_hdtr)); + bzero(&header_iovec, sizeof(header_iovec)); + header_iovec[0].iov_base = HTTP_OK; + header_iovec[0].iov_len = strlen(HTTP_OK); + header_iovec[1].iov_base = HTTP_SERVER; + header_iovec[1].iov_len = strlen(HTTP_SERVER); + header_iovec[2].iov_base = HTTP_CONNECTION; + header_iovec[2].iov_len = strlen(HTTP_CONNECTION); + header_iovec[3].iov_base = HTTP_CONTENT; + header_iovec[3].iov_len = strlen(HTTP_CONTENT); + sf_hdtr.headers = header_iovec; + sf_hdtr.hdr_cnt = 4; + sf_hdtr.trailers = NULL; + sf_hdtr.trl_cnt = 0; + + if (sendfile(data_file, sock, 0, 0, &sf_hdtr, NULL, 0) < 0) warn("sendfile"); return (0);