diff options
author | Florent Le Coz <louiz@louiz.org> | 2014-02-28 01:14:38 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2014-02-28 01:14:38 +0100 |
commit | 86d4347af8532ef85472e47c01d645fa5ad1b3b1 (patch) | |
tree | ddc9e019b89b216bed33911a2e2aeb03c668443c /src/xmpp/xmpp_component.cpp | |
parent | df774d45a9754274a1701d801e4a42e71d38c97c (diff) | |
download | biboumi-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_component.cpp')
-rw-r--r-- | src/xmpp/xmpp_component.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/xmpp/xmpp_component.cpp b/src/xmpp/xmpp_component.cpp index 9b73626..cd424ed 100644 --- a/src/xmpp/xmpp_component.cpp +++ b/src/xmpp/xmpp_component.cpp @@ -89,10 +89,20 @@ void XmppComponent::on_connection_close() log_info("XMPP server closed connection"); } -void XmppComponent::parse_in_buffer() +void XmppComponent::parse_in_buffer(const size_t size) { - this->parser.feed(this->in_buf.data(), this->in_buf.size(), false); - this->in_buf.clear(); + if (!this->in_buf.empty()) + { // This may happen if the parser could not allocate enough space for + // us. We try to feed it the data that was read into our in_buf + // instead. If this fails again we are in trouble. + this->parser.feed(this->in_buf.data(), this->in_buf.size(), false); + this->in_buf.clear(); + } + else + { // Just tell the parser to parse the data that was placed into the + // buffer it provided to us with GetBuffer + this->parser.parse(size, false); + } } void XmppComponent::shutdown() @@ -308,6 +318,11 @@ Bridge* XmppComponent::get_user_bridge(const std::string& user_jid) } } +void* XmppComponent::get_receive_buffer(const size_t size) const +{ + return this->parser.get_buffer(size); +} + void XmppComponent::send_message(const std::string& from, Xmpp::body&& body, const std::string& to) { XmlNode node("message"); |