summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-07-15 15:39:25 +0200
committerFlorent Le Coz <louiz@louiz.org>2014-07-15 15:39:25 +0200
commit11a31db2d5bcc158bb8902e74f192dbc82827f53 (patch)
tree045aa047a7a63c80c501d9f8be30e3cb2ac95ce8 /src/network
parent4582f1079767f53bb6bd9b96c358ea3c641aaa96 (diff)
downloadbiboumi-11a31db2d5bcc158bb8902e74f192dbc82827f53.tar.gz
biboumi-11a31db2d5bcc158bb8902e74f192dbc82827f53.tar.bz2
biboumi-11a31db2d5bcc158bb8902e74f192dbc82827f53.tar.xz
biboumi-11a31db2d5bcc158bb8902e74f192dbc82827f53.zip
Send the reason of the connection close to the user
Diffstat (limited to 'src/network')
-rw-r--r--src/network/tcp_socket_handler.cpp15
-rw-r--r--src/network/tcp_socket_handler.hpp2
2 files changed, 6 insertions, 11 deletions
diff --git a/src/network/tcp_socket_handler.cpp b/src/network/tcp_socket_handler.cpp
index d9432a6..01adf04 100644
--- a/src/network/tcp_socket_handler.cpp
+++ b/src/network/tcp_socket_handler.cpp
@@ -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);
if (0 == size)
{
- this->on_connection_close();
+ this->on_connection_close("");
this->close();
}
else if (-1 == size)
{
log_warning("Error while reading from socket: " << strerror(errno));
+ this->close();
if (this->connecting)
- {
- this->close();
- this->on_connection_failed(strerror(errno));
- }
+ this->on_connection_failed(strerror(errno));
else
- {
- this->close();
- this->on_connection_close();
- }
+ this->on_connection_close(strerror(errno));
}
return size;
}
@@ -245,7 +240,7 @@ void TCPSocketHandler::on_send()
if (res < 0)
{
log_error("sendmsg failed: " << strerror(errno));
- this->on_connection_close();
+ this->on_connection_close(strerror(errno));
this->close();
}
else
diff --git a/src/network/tcp_socket_handler.hpp b/src/network/tcp_socket_handler.hpp
index 8416690..876cd57 100644
--- a/src/network/tcp_socket_handler.hpp
+++ b/src/network/tcp_socket_handler.hpp
@@ -96,7 +96,7 @@ public:
/**
* 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
* may be in the in_buf buffer, or somewhere else, depending on what