From 12ab556477d8ffc620a84d29ac8abfaefeb4985f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 15 Oct 2013 22:18:37 +0200 Subject: event/BufferedSocket: pass writable pointer to OnSocketInput() Remove the const_cast from HttpdClient.cxx, and avoid one allocation in ClientRead.cxx. --- src/ClientRead.cxx | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/ClientRead.cxx') diff --git a/src/ClientRead.cxx b/src/ClientRead.cxx index 8f7c4cf7e..af2e572a2 100644 --- a/src/ClientRead.cxx +++ b/src/ClientRead.cxx @@ -22,27 +22,25 @@ #include "Main.hxx" #include "event/Loop.hxx" -#include - #include #include BufferedSocket::InputResult -Client::OnSocketInput(const void *data, size_t length) +Client::OnSocketInput(void *data, size_t length) { - const char *p = (const char *)data; - const char *newline = (const char *)memchr(p, '\n', length); + char *p = (char *)data; + char *newline = (char *)memchr(p, '\n', length); if (newline == NULL) return InputResult::MORE; TimeoutMonitor::ScheduleSeconds(client_timeout); - char *line = g_strndup(p, newline - p); - BufferedSocket::ConsumeInput(newline + 1 - p); + /* terminate the string at the end of the line */ + *newline = 0; - enum command_return result = client_process_line(this, line); - g_free(line); + BufferedSocket::ConsumeInput(newline + 1 - p); + enum command_return result = client_process_line(this, p); switch (result) { case COMMAND_RETURN_OK: case COMMAND_RETURN_IDLE: -- cgit v1.2.3