Do not send data if we are connected, send it only once we actually are

This commit is contained in:
Florent Le Coz
2014-03-24 18:37:31 +01:00
parent 3b1bf740a3
commit e196d2f1f4
4 changed files with 17 additions and 1 deletions
+1
View File
@@ -45,6 +45,7 @@ void IrcClient::on_connected()
this->send_nick_command(this->username); this->send_nick_command(this->username);
this->send_user_command(this->username, this->username); this->send_user_command(this->username, this->username);
this->send_gateway_message("Connected to IRC server."); this->send_gateway_message("Connected to IRC server.");
this->send_pending_data();
} }
void IrcClient::on_connection_close() void IrcClient::on_connection_close()
+7
View File
@@ -238,6 +238,13 @@ void SocketHandler::send_data(std::string&& data)
if (data.empty()) if (data.empty())
return ; return ;
this->out_buf.emplace_back(std::move(data)); this->out_buf.emplace_back(std::move(data));
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); this->poller->watch_send_events(this);
} }
+4
View File
@@ -51,6 +51,10 @@ public:
* notified when a send event is ready. * notified when a send event is ready.
*/ */
void send_data(std::string&& data); 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. * Returns the socket that should be handled by the poller.
*/ */
+4
View File
@@ -82,6 +82,9 @@ void XmppComponent::on_connected()
node["to"] = this->served_hostname; node["to"] = this->served_hostname;
this->send_stanza(node); this->send_stanza(node);
this->doc_open = true; 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() 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) void XmppComponent::on_remote_stream_close(const XmlNode& node)
{ {
log_debug("XMPP DOCUMENT CLOSE " << node.to_string()); log_debug("XMPP DOCUMENT CLOSE " << node.to_string());
this->doc_open = false;
} }
void XmppComponent::on_stanza(const Stanza& stanza) void XmppComponent::on_stanza(const Stanza& stanza)