summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2020-05-10 19:39:55 +0200
committerLeah Neukirchen <leah@vuxu.org>2020-05-10 19:44:50 +0200
commit3a48e15c894b85f2a98f2f2cc8e9fc0529e82345 (patch)
treea1b8c54c1ec3ef93dd367d841d4d6ae81b918ce1
parentce0727e85233aaeddfcc5b72c818472fc55bf102 (diff)
downloadhittpd-3a48e15c894b85f2a98f2f2cc8e9fc0529e82345.tar.gz
hittpd-3a48e15c894b85f2a98f2f2cc8e9fc0529e82345.tar.xz
hittpd-3a48e15c894b85f2a98f2f2cc8e9fc0529e82345.zip
compute timestamp once per iteration
-rw-r--r--hittpd.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/hittpd.c b/hittpd.c
index d6c3fa1..87c9b3f 100644
--- a/hittpd.c
+++ b/hittpd.c
@@ -246,6 +246,9 @@ content_length(struct conn_data *data)
 	return data->last - data->first;
 }
 
+time_t now;
+char timestamp[64];
+
 void
 accesslog(http_parser *p, int status)
 {
@@ -255,8 +258,7 @@ accesslog(http_parser *p, int status)
 	struct conn_data *data = p->data;
 
 	char buf[64];
-	time_t t = time(0);
-	strftime(buf, 64, "[%d/%b/%Y:%H:%M:%S %z]", localtime(&t));
+	strftime(buf, 64, "[%d/%b/%Y:%H:%M:%S %z]", localtime(&now));
 
 //	REMOTEHOST - - [DD/MON/YYYY:HH:MM:SS -TZ] "METHOD PATH" STATUS BYTES
 // ?    REFERER USER_AGENT
@@ -285,9 +287,6 @@ send_response(http_parser *p, int status, const char *msg,
 	struct conn_data *data = p->data;
 	char buf[2048];
 
-	char now[64];
-	httpdate(time(0), now);
-
 	if (content) {
 		data->first = 0;
 		data->last = strlen(content);
@@ -305,7 +304,7 @@ send_response(http_parser *p, int status, const char *msg,
 	    p->http_major,
 	    p->http_minor,
 	    status, msg,
-	    now,
+	    timestamp,
 	    extra_headers);
 
 	if (len >= (int)sizeof buf) {
@@ -664,7 +663,7 @@ on_message_complete(http_parser *p) {
 		data->buf = buf;
 		data->first = 0;
 		data->last = len;
-		send_ok(p, time(0), "text/html", len);
+		send_ok(p, now, "text/html", len);
 
 		return 0;
 	}
@@ -778,7 +777,7 @@ accept_client(int i, int fd)
 	datas[i].fd = fd;
 	datas[i].stream_fd = -1;
 	datas[i].last = -1;
-	datas[i].deadline = time(0) + TIMEOUT;
+	datas[i].deadline = now + TIMEOUT;
 
 	parsers[i].data = &datas[i];
 
@@ -1008,7 +1007,8 @@ main(int argc, char *argv[])
 			}
 		}
 
-		time_t now = time(0);
+		now = time(0);
+		httpdate(now, timestamp);
 
 		if (nready == 0) {
 			// clear timeouted