Send the reason of the connection close to the user
This commit is contained in:
@@ -93,9 +93,11 @@ void IrcClient::on_connected()
|
|||||||
this->send_pending_data();
|
this->send_pending_data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IrcClient::on_connection_close()
|
void IrcClient::on_connection_close(const std::string& error_msg)
|
||||||
{
|
{
|
||||||
static const std::string message = "Connection closed by remote server.";
|
std::string message = "Connection closed by remote server.";
|
||||||
|
if (!error_msg.empty())
|
||||||
|
message += ": " + error_msg;
|
||||||
const IrcMessage error{"ERROR", {message}};
|
const IrcMessage error{"ERROR", {message}};
|
||||||
this->on_error(error);
|
this->on_error(error);
|
||||||
log_warning(message);
|
log_warning(message);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Close the connection, remove us from the poller
|
* Close the connection, remove us from the poller
|
||||||
*/
|
*/
|
||||||
void on_connection_close() override final;
|
void on_connection_close(const std::string& error) override final;
|
||||||
/**
|
/**
|
||||||
* Parse the data we have received so far and try to get one or more
|
* Parse the data we have received so far and try to get one or more
|
||||||
* complete messages from it.
|
* complete messages from it.
|
||||||
|
|||||||
@@ -207,22 +207,17 @@ ssize_t TCPSocketHandler::do_recv(void* recv_buf, const size_t buf_size)
|
|||||||
ssize_t size = ::recv(this->socket, recv_buf, buf_size, 0);
|
ssize_t size = ::recv(this->socket, recv_buf, buf_size, 0);
|
||||||
if (0 == size)
|
if (0 == size)
|
||||||
{
|
{
|
||||||
this->on_connection_close();
|
this->on_connection_close("");
|
||||||
this->close();
|
this->close();
|
||||||
}
|
}
|
||||||
else if (-1 == size)
|
else if (-1 == size)
|
||||||
{
|
{
|
||||||
log_warning("Error while reading from socket: " << strerror(errno));
|
log_warning("Error while reading from socket: " << strerror(errno));
|
||||||
|
this->close();
|
||||||
if (this->connecting)
|
if (this->connecting)
|
||||||
{
|
|
||||||
this->close();
|
|
||||||
this->on_connection_failed(strerror(errno));
|
this->on_connection_failed(strerror(errno));
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
this->on_connection_close(strerror(errno));
|
||||||
this->close();
|
|
||||||
this->on_connection_close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
@@ -245,7 +240,7 @@ void TCPSocketHandler::on_send()
|
|||||||
if (res < 0)
|
if (res < 0)
|
||||||
{
|
{
|
||||||
log_error("sendmsg failed: " << strerror(errno));
|
log_error("sendmsg failed: " << strerror(errno));
|
||||||
this->on_connection_close();
|
this->on_connection_close(strerror(errno));
|
||||||
this->close();
|
this->close();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Called when we detect a disconnection from the remote host.
|
* Called when we detect a disconnection from the remote host.
|
||||||
*/
|
*/
|
||||||
virtual void on_connection_close() = 0;
|
virtual void on_connection_close(const std::string& error) = 0;
|
||||||
/**
|
/**
|
||||||
* Handle/consume (some of) the data received so far. The data to handle
|
* Handle/consume (some of) the data received so far. The data to handle
|
||||||
* may be in the in_buf buffer, or somewhere else, depending on what
|
* may be in the in_buf buffer, or somewhere else, depending on what
|
||||||
|
|||||||
@@ -108,10 +108,17 @@ void XmppComponent::on_connected()
|
|||||||
this->send_pending_data();
|
this->send_pending_data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmppComponent::on_connection_close()
|
void XmppComponent::on_connection_close(const std::string& error)
|
||||||
|
{
|
||||||
|
if (error.empty())
|
||||||
{
|
{
|
||||||
log_info("XMPP server closed connection");
|
log_info("XMPP server closed connection");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log_info("XMPP server closed connection: " << error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void XmppComponent::parse_in_buffer(const size_t size)
|
void XmppComponent::parse_in_buffer(const size_t size)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public:
|
|||||||
|
|
||||||
void on_connection_failed(const std::string& reason) override final;
|
void on_connection_failed(const std::string& reason) override final;
|
||||||
void on_connected() override final;
|
void on_connected() override final;
|
||||||
void on_connection_close() override final;
|
void on_connection_close(const std::string& error) override final;
|
||||||
void parse_in_buffer(const size_t size) override final;
|
void parse_in_buffer(const size_t size) override final;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user