aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-10-15 22:18:37 +0200
committerMax Kellermann <max@duempel.org>2013-10-15 22:47:46 +0200
commit12ab556477d8ffc620a84d29ac8abfaefeb4985f (patch)
tree189a4507770628f430484d92a8e7524c9fbdee57 /src
parent509f8dab8946cfc311def89f62352c0881e73348 (diff)
downloadmpd-12ab556477d8ffc620a84d29ac8abfaefeb4985f.tar.gz
mpd-12ab556477d8ffc620a84d29ac8abfaefeb4985f.tar.xz
mpd-12ab556477d8ffc620a84d29ac8abfaefeb4985f.zip
event/BufferedSocket: pass writable pointer to OnSocketInput()
Remove the const_cast from HttpdClient.cxx, and avoid one allocation in ClientRead.cxx.
Diffstat (limited to 'src')
-rw-r--r--src/ClientInternal.hxx3
-rw-r--r--src/ClientRead.cxx16
-rw-r--r--src/event/BufferedSocket.hxx10
-rw-r--r--src/output/HttpdClient.cxx11
-rw-r--r--src/output/HttpdClient.hxx3
5 files changed, 23 insertions, 20 deletions
diff --git a/src/ClientInternal.hxx b/src/ClientInternal.hxx
index e4c2525b4..37054fc00 100644
--- a/src/ClientInternal.hxx
+++ b/src/ClientInternal.hxx
@@ -111,8 +111,7 @@ public:
private:
/* virtual methods from class BufferedSocket */
- virtual InputResult OnSocketInput(const void *data,
- size_t length) override;
+ virtual InputResult OnSocketInput(void *data, size_t length) override;
virtual void OnSocketError(Error &&error) override;
virtual void OnSocketClosed() override;
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 <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);
- 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:
diff --git a/src/event/BufferedSocket.hxx b/src/event/BufferedSocket.hxx
index 31d6c3c57..db920f981 100644
--- a/src/event/BufferedSocket.hxx
+++ b/src/event/BufferedSocket.hxx
@@ -101,7 +101,15 @@ protected:
CLOSED,
};
- virtual InputResult OnSocketInput(const void *data, size_t length) = 0;
+ /**
+ * Data has been received on the socket.
+ *
+ * @param data a pointer to the beginning of the buffer; the
+ * buffer may be modified by the method while it processes the
+ * data
+ */
+ virtual InputResult OnSocketInput(void *data, size_t length) = 0;
+
virtual void OnSocketError(Error &&error) = 0;
virtual void OnSocketClosed() = 0;
diff --git a/src/output/HttpdClient.cxx b/src/output/HttpdClient.cxx
index 5b65cc956..c622f823a 100644
--- a/src/output/HttpdClient.cxx
+++ b/src/output/HttpdClient.cxx
@@ -402,7 +402,7 @@ HttpdClient::OnSocketReady(unsigned flags)
}
BufferedSocket::InputResult
-HttpdClient::OnSocketInput(const void *data, size_t length)
+HttpdClient::OnSocketInput(void *data, size_t length)
{
if (state == RESPONSE) {
LogWarning(httpd_output_domain,
@@ -411,8 +411,8 @@ HttpdClient::OnSocketInput(const void *data, size_t length)
return InputResult::CLOSED;
}
- const char *line = (const char *)data;
- const char *newline = (const char *)memchr(line, '\n', length);
+ char *line = (char *)data;
+ char *newline = (char *)memchr(line, '\n', length);
if (newline == nullptr)
return InputResult::MORE;
@@ -421,9 +421,8 @@ HttpdClient::OnSocketInput(const void *data, size_t length)
if (newline > line && newline[-1] == '\r')
--newline;
- /* terminate the string at the end of the line; the const_cast
- is a dirty hack */
- *const_cast<char *>(newline) = 0;
+ /* terminate the string at the end of the line */
+ *newline = 0;
if (!HandleLine(line)) {
assert(state == RESPONSE);
diff --git a/src/output/HttpdClient.hxx b/src/output/HttpdClient.hxx
index d481898a2..90295fdf7 100644
--- a/src/output/HttpdClient.hxx
+++ b/src/output/HttpdClient.hxx
@@ -177,8 +177,7 @@ public:
protected:
virtual bool OnSocketReady(unsigned flags) override;
- virtual InputResult OnSocketInput(const void *data,
- size_t length) override;
+ virtual InputResult OnSocketInput(void *data, size_t length) override;
virtual void OnSocketError(Error &&error) override;
virtual void OnSocketClosed() override;
};