event/BufferedSocket: pass writable pointer to OnSocketInput()

Remove the const_cast from HttpdClient.cxx, and avoid one allocation
in ClientRead.cxx.
This commit is contained in:
Max Kellermann
2013-10-15 22:18:37 +02:00
parent 509f8dab89
commit 12ab556477
5 changed files with 23 additions and 20 deletions

View File

@@ -22,27 +22,25 @@
#include "Main.hxx"
#include "event/Loop.hxx"
#include <glib.h>
#include <assert.h>
#include <string.h>
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);
/* terminate the string at the end of the line */
*newline = 0;
BufferedSocket::ConsumeInput(newline + 1 - p);
enum command_return result = client_process_line(this, line);
g_free(line);
enum command_return result = client_process_line(this, p);
switch (result) {
case COMMAND_RETURN_OK:
case COMMAND_RETURN_IDLE: