From 3f243081d85ca02188ccdd61ae3476ed9df933e1 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Fri, 25 Oct 2019 02:27:05 -0400 Subject: Implement client reading from ring buffer It's still messy but it works!! --- client.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'client.c') 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); + } +} -- cgit 1.4.1