From 28f009d1644f4503d3b1376818736401f0987c22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christophe=20Gu=C3=A9bert?= Date: Mon, 2 Jan 2017 10:52:45 +0100 Subject: [PATCH] Throw a SocketClosed exception when the socket is closed before receiving an association abort. --- examples/genericscp.cpp | 5 +++++ src/odil/dul/Transport.cpp | 5 +++++ src/odil/dul/Transport.h | 16 ++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/examples/genericscp.cpp b/examples/genericscp.cpp index 3bd0a3c0..b466bedd 100644 --- a/examples/genericscp.cpp +++ b/examples/genericscp.cpp @@ -124,6 +124,11 @@ int main() { dispatcher.dispatch(); } + catch(odil::dul::SocketClosed const &) + { + std::cout << "Peer closed the socket" << std::endl; + done = true; + } catch(odil::AssociationReleased const &) { std::cout << "Peer released association" << std::endl; diff --git a/src/odil/dul/Transport.cpp b/src/odil/dul/Transport.cpp index 6b56f150..a25ed4b3 100644 --- a/src/odil/dul/Transport.cpp +++ b/src/odil/dul/Transport.cpp @@ -262,6 +262,11 @@ ::_run(Source & source, boost::system::error_code & error) if(source == Source::OPERATION) { + if(error == boost::asio::error::eof) + { + throw SocketClosed(); + } + if(error) { throw Exception("Operation error: "+error.message()); diff --git a/src/odil/dul/Transport.h b/src/odil/dul/Transport.h index 8b9d046a..95edfbaf 100644 --- a/src/odil/dul/Transport.h +++ b/src/odil/dul/Transport.h @@ -15,6 +15,8 @@ #include #include +#include "odil/Exception.h" + namespace odil { @@ -102,6 +104,20 @@ struct Transport void _run(Source & source, boost::system::error_code & error); }; + +/** + * @brief Exception reported when the socket is closed without releasing the association. + */ +class SocketClosed: public Exception +{ +public: + SocketClosed() + : Exception("Socket closed") + { + // Nothing else. + } +}; + } }