summaryrefslogtreecommitdiff
path: root/src/xmpp/xmpp_parser.cpp
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-02-28 01:14:38 +0100
committerFlorent Le Coz <louiz@louiz.org>2014-02-28 01:14:38 +0100
commit86d4347af8532ef85472e47c01d645fa5ad1b3b1 (patch)
treeddc9e019b89b216bed33911a2e2aeb03c668443c /src/xmpp/xmpp_parser.cpp
parentdf774d45a9754274a1701d801e4a42e71d38c97c (diff)
downloadbiboumi-86d4347af8532ef85472e47c01d645fa5ad1b3b1.tar.gz
biboumi-86d4347af8532ef85472e47c01d645fa5ad1b3b1.tar.bz2
biboumi-86d4347af8532ef85472e47c01d645fa5ad1b3b1.tar.xz
biboumi-86d4347af8532ef85472e47c01d645fa5ad1b3b1.zip
Avoid unnecessary copies by recv()ing data directly into the expat buffer
Diffstat (limited to 'src/xmpp/xmpp_parser.cpp')
-rw-r--r--src/xmpp/xmpp_parser.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/xmpp/xmpp_parser.cpp b/src/xmpp/xmpp_parser.cpp
index 6e4809d..9fcc16c 100644
--- a/src/xmpp/xmpp_parser.cpp
+++ b/src/xmpp/xmpp_parser.cpp
@@ -1,6 +1,8 @@
#include <xmpp/xmpp_parser.hpp>
#include <xmpp/xmpp_stanza.hpp>
+#include <logger/logger.hpp>
+
/**
* Expat handlers. Called by the Expat library, never by ourself.
* They just forward the call to the XmppParser corresponding methods.
@@ -45,9 +47,25 @@ XmppParser::~XmppParser()
XML_ParserFree(this->parser);
}
-void XmppParser::feed(const char* data, const int len, const bool is_final)
+int XmppParser::feed(const char* data, const int len, const bool is_final)
+{
+ int res = XML_Parse(this->parser, data, len, is_final);
+ if (res == 0)
+ log_error("Xml_Parse encountered an error");
+ return res;
+}
+
+int XmppParser::parse(const int len, const bool is_final)
+{
+ int res = XML_ParseBuffer(this->parser, len, is_final);
+ if (res == 0)
+ log_error("Xml_Parsebuffer encountered an error");
+ return res;
+}
+
+void* XmppParser::get_buffer(const size_t size) const
{
- XML_Parse(this->parser, data, len, is_final);
+ return XML_GetBuffer(this->parser, static_cast<int>(size));
}
void XmppParser::start_element(const XML_Char* name, const XML_Char** attribute)