summary refs log tree commit diff
path: root/client.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-10-25 02:27:05 -0400
committerJune McEnroe <june@causal.agency>2019-10-25 02:27:05 -0400
commit3f243081d85ca02188ccdd61ae3476ed9df933e1 (patch)
treee3adbde6da2c302255ee31d9db1f4fbe5ae45a37 /client.c
parentImplement ringDiff and ringRead (diff)
downloadpounce-3f243081d85ca02188ccdd61ae3476ed9df933e1.tar.gz
pounce-3f243081d85ca02188ccdd61ae3476ed9df933e1.zip
Implement client reading from ring buffer
It's still messy but it works!!
Diffstat (limited to '')
-rw-r--r--client.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/client.c b/client.c
index 4bb1f54..cdf0009 100644
--- a/client.c
+++ b/client.c
@@ -119,6 +119,7 @@ static void handleUser(struct Client *client, struct Message msg) {
 }
 
 static void handlePass(struct Client *client, struct Message msg) {
+	if (!clientPass) return;
 	if (!msg.params[0] || strcmp(clientPass, msg.params[0])) {
 		passRequired(client);
 	} else {
@@ -227,3 +228,23 @@ void clientRecv(struct Client *client) {
 	client->len -= line - client->buf;
 	memmove(client->buf, line, client->len);
 }
+
+size_t clientDiff(const struct Client *client) {
+	if (client->need) return 0;
+	return ringDiff(client->reader);
+}
+
+// TODO: Read several lines based on LOWAT for POLLOUT?
+void clientRead(struct Client *client) {
+	time_t time;
+	const char *line = ringRead(&time, client->reader);
+	if (!line) return;
+	if (client->serverTime) {
+		char ts[sizeof("YYYY-MM-DDThh:mm:ss.sssZ")];
+		struct tm *tm = gmtime(&time);
+		strftime(ts, sizeof(ts), "%FT%T.000Z", tm);
+		clientFormat(client, "@time=%s %s\r\n", ts, line);
+	} else {
+		clientFormat(client, "%s\r\n", line);
+	}
+}