summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-03-24 18:37:31 +0100
committerFlorent Le Coz <louiz@louiz.org>2014-03-24 18:37:31 +0100
commite196d2f1f400f5c9634ed42fcbdf5c5fb63a13fb (patch)
treef9a7d32d4bb9d480df36ac4dbc0fa6d8a5149200 /src
parent3b1bf740a3299e3373916fd343492420550464e1 (diff)
downloadbiboumi-e196d2f1f400f5c9634ed42fcbdf5c5fb63a13fb.tar.gz
biboumi-e196d2f1f400f5c9634ed42fcbdf5c5fb63a13fb.tar.bz2
biboumi-e196d2f1f400f5c9634ed42fcbdf5c5fb63a13fb.tar.xz
biboumi-e196d2f1f400f5c9634ed42fcbdf5c5fb63a13fb.zip
Do not send data if we are connected, send it only once we actually are
Diffstat (limited to 'src')
-rw-r--r--src/irc/irc_client.cpp1
-rw-r--r--src/network/socket_handler.cpp9
-rw-r--r--src/network/socket_handler.hpp4
-rw-r--r--src/xmpp/xmpp_component.cpp4
4 files changed, 17 insertions, 1 deletions
diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp
index 0c36372..3737b91 100644
--- a/src/irc/irc_client.cpp
+++ b/src/irc/irc_client.cpp
@@ -45,6 +45,7 @@ void IrcClient::on_connected()
this->send_nick_command(this->username);
this->send_user_command(this->username, this->username);
this->send_gateway_message("Connected to IRC server.");
+ this->send_pending_data();
}
void IrcClient::on_connection_close()
diff --git a/src/network/socket_handler.cpp b/src/network/socket_handler.cpp
index 3f4c01d..f344786 100644
--- a/src/network/socket_handler.cpp
+++ b/src/network/socket_handler.cpp
@@ -238,7 +238,14 @@ void SocketHandler::send_data(std::string&& data)
if (data.empty())
return ;
this->out_buf.emplace_back(std::move(data));
- this->poller->watch_send_events(this);
+ if (this->connected)
+ this->poller->watch_send_events(this);
+}
+
+void SocketHandler::send_pending_data()
+{
+ if (this->connected && !this->out_buf.empty())
+ this->poller->watch_send_events(this);
}
bool SocketHandler::is_connected() const
diff --git a/src/network/socket_handler.hpp b/src/network/socket_handler.hpp
index 35b0fdc..f554350 100644
--- a/src/network/socket_handler.hpp
+++ b/src/network/socket_handler.hpp
@@ -52,6 +52,10 @@ public:
*/
void send_data(std::string&& data);
/**
+ * Watch the socket for send events, if our out buffer is not empty.
+ */
+ void send_pending_data();
+ /**
* Returns the socket that should be handled by the poller.
*/
socket_t get_socket() const;
diff --git a/src/xmpp/xmpp_component.cpp b/src/xmpp/xmpp_component.cpp
index cd424ed..d30f778 100644
--- a/src/xmpp/xmpp_component.cpp
+++ b/src/xmpp/xmpp_component.cpp
@@ -82,6 +82,9 @@ void XmppComponent::on_connected()
node["to"] = this->served_hostname;
this->send_stanza(node);
this->doc_open = true;
+ // We may have some pending data to send: this happens when we try to send
+ // some data before we are actually connected. We send that data right now, if any
+ this->send_pending_data();
}
void XmppComponent::on_connection_close()
@@ -161,6 +164,7 @@ void XmppComponent::on_remote_stream_open(const XmlNode& node)
void XmppComponent::on_remote_stream_close(const XmlNode& node)
{
log_debug("XMPP DOCUMENT CLOSE " << node.to_string());
+ this->doc_open = false;
}
void XmppComponent::on_stanza(const Stanza& stanza)