Remove disconnected IrcClients
This commit is contained in:
@@ -29,6 +29,19 @@ void Bridge::shutdown()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Bridge::clean()
|
||||||
|
{
|
||||||
|
auto it = this->irc_clients.begin();
|
||||||
|
while (it != this->irc_clients.end())
|
||||||
|
{
|
||||||
|
IrcClient* client = it->second.get();
|
||||||
|
if (!client->is_connected())
|
||||||
|
it = this->irc_clients.erase(it);
|
||||||
|
else
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Xmpp::body Bridge::make_xmpp_body(const std::string& str)
|
Xmpp::body Bridge::make_xmpp_body(const std::string& str)
|
||||||
{
|
{
|
||||||
std::string res;
|
std::string res;
|
||||||
|
|||||||
@@ -28,7 +28,10 @@ public:
|
|||||||
* QUIT all connected IRC servers.
|
* QUIT all connected IRC servers.
|
||||||
*/
|
*/
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
/**
|
||||||
|
* Remove all inactive IrcClients
|
||||||
|
*/
|
||||||
|
void clean();
|
||||||
static Xmpp::body make_xmpp_body(const std::string& str);
|
static Xmpp::body make_xmpp_body(const std::string& str);
|
||||||
/***
|
/***
|
||||||
**
|
**
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ IrcChannel* IrcClient::get_channel(const std::string& name)
|
|||||||
|
|
||||||
bool IrcClient::is_channel_joined(const std::string& name)
|
bool IrcClient::is_channel_joined(const std::string& name)
|
||||||
{
|
{
|
||||||
IrcChannel* client = this->get_channel(name);
|
IrcChannel* channel = this->get_channel(name);
|
||||||
return client->joined;
|
return channel->joined;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string IrcClient::get_own_nick() const
|
std::string IrcClient::get_own_nick() const
|
||||||
@@ -339,7 +339,12 @@ void IrcClient::on_part(const IrcMessage& message)
|
|||||||
bool self = channel->get_self()->nick == nick;
|
bool self = channel->get_self()->nick == nick;
|
||||||
this->bridge->send_muc_leave(std::move(iid), std::move(nick), std::move(txt), self);
|
this->bridge->send_muc_leave(std::move(iid), std::move(nick), std::move(txt), self);
|
||||||
if (self)
|
if (self)
|
||||||
|
{
|
||||||
channel->joined = false;
|
channel->joined = false;
|
||||||
|
this->channels.erase(chan_name);
|
||||||
|
// channel pointer is now invalid
|
||||||
|
channel = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,6 +363,7 @@ void IrcClient::on_error(const IrcMessage& message)
|
|||||||
std::string own_nick = channel->get_self()->nick;
|
std::string own_nick = channel->get_self()->nick;
|
||||||
this->bridge->send_muc_leave(std::move(iid), std::move(own_nick), leave_message, true);
|
this->bridge->send_muc_leave(std::move(iid), std::move(own_nick), leave_message, true);
|
||||||
}
|
}
|
||||||
|
this->channels.clear();
|
||||||
this->send_gateway_message(std::string("ERROR: ") + leave_message);
|
this->send_gateway_message(std::string("ERROR: ") + leave_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,9 @@ int main(int ac, char** av)
|
|||||||
const std::chrono::milliseconds timeout(-1);
|
const std::chrono::milliseconds timeout(-1);
|
||||||
while (p.poll(timeout) != -1 || !exiting)
|
while (p.poll(timeout) != -1 || !exiting)
|
||||||
{
|
{
|
||||||
|
// Check for empty irc_clients (not connected, or with no joined
|
||||||
|
// channel) and remove them
|
||||||
|
xmpp_component->clean();
|
||||||
if (stop)
|
if (stop)
|
||||||
{
|
{
|
||||||
log_info("Signal received, exiting...");
|
log_info("Signal received, exiting...");
|
||||||
|
|||||||
@@ -94,6 +94,14 @@ void XmppComponent::shutdown()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XmppComponent::clean()
|
||||||
|
{
|
||||||
|
for (auto it = this->bridges.begin(); it != this->bridges.end(); ++it)
|
||||||
|
{
|
||||||
|
it->second->clean();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void XmppComponent::on_remote_stream_open(const XmlNode& node)
|
void XmppComponent::on_remote_stream_open(const XmlNode& node)
|
||||||
{
|
{
|
||||||
log_debug("XMPP DOCUMENT OPEN: " << node.to_string());
|
log_debug("XMPP DOCUMENT OPEN: " << node.to_string());
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
void shutdown();
|
void shutdown();
|
||||||
bool is_document_open() const;
|
bool is_document_open() const;
|
||||||
|
/**
|
||||||
|
* Run a check on all bridges, to remove all disconnected (socket is
|
||||||
|
* closed, or no channel is joined) IrcClients. Some kind of garbage collector.
|
||||||
|
*/
|
||||||
|
void clean();
|
||||||
/**
|
/**
|
||||||
* Connect to the XMPP server.
|
* Connect to the XMPP server.
|
||||||
* Returns false if we failed to connect
|
* Returns false if we failed to connect
|
||||||
|
|||||||
Reference in New Issue
Block a user