diff options
author | Nikita Vaganov <nvaganov@luxoft.com> | 2014-06-27 15:57:19 +0400 |
---|---|---|
committer | Nikita Vaganov <nvaganov@luxoft.com> | 2014-06-27 15:57:19 +0400 |
commit | cf5de655fcd5e07a4f3b15c81a703398b1e28f7d (patch) | |
tree | 25427f1278d27ec191547cc58225cf45bf4baf97 | |
parent | a3c41f267d66f57df2642dea042d60fab6709deb (diff) | |
download | sdl_core-cf5de655fcd5e07a4f3b15c81a703398b1e28f7d.tar.gz |
iAP2 disconnect detection added
3 files changed, 42 insertions, 16 deletions
diff --git a/src/components/connection_handler/src/connection_handler_impl.cc b/src/components/connection_handler/src/connection_handler_impl.cc index a4bf08516f..4ef1fae01d 100644 --- a/src/components/connection_handler/src/connection_handler_impl.cc +++ b/src/components/connection_handler/src/connection_handler_impl.cc @@ -191,6 +191,8 @@ void ConnectionHandlerImpl::OnUnexpectedDisconnect( transport_manager::ConnectionUID connection_id, const transport_manager::CommunicationError& error) { LOG4CXX_ERROR(logger_, "ConnectionHandlerImpl::OnUnexpectedDisconnect"); + + OnConnectionEnded(connection_id); } void ConnectionHandlerImpl::OnDeviceConnectionLost( diff --git a/src/components/transport_manager/include/transport_manager/mme/iap2_connection.h b/src/components/transport_manager/include/transport_manager/mme/iap2_connection.h index f894bd5f30..1d959605f8 100644 --- a/src/components/transport_manager/include/transport_manager/mme/iap2_connection.h +++ b/src/components/transport_manager/include/transport_manager/mme/iap2_connection.h @@ -63,6 +63,7 @@ class IAP2Connection : public Connection { static const size_t kBufferSize = 1024; void ReceiveData(); + bool Close(); DeviceUID device_uid_; ApplicationHandle app_handle_; @@ -73,6 +74,7 @@ class IAP2Connection : public Connection { uint8_t buffer_[kBufferSize]; utils::SharedPtr<threads::Thread> receiver_thread_; + threads::ThreadDelegate* receiver_thread_delegate_; class ReceiverThreadDelegate : public threads::PulseThreadDelegate { public: diff --git a/src/components/transport_manager/src/mme/iap2_connection.cc b/src/components/transport_manager/src/mme/iap2_connection.cc index 0d359bbd15..056211c544 100644 --- a/src/components/transport_manager/src/mme/iap2_connection.cc +++ b/src/components/transport_manager/src/mme/iap2_connection.cc @@ -30,6 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include <errno.h> + #include "utils/logger.h" #include "transport_manager/mme/iap2_connection.h" @@ -56,8 +58,8 @@ bool IAP2Connection::Init() { protocol_name_ = record.first; iap2ea_hdl_ = record.second; std::string thread_name = "iAP2 receiver (" + protocol_name_ + ")"; - receiver_thread_ = new threads::Thread(thread_name.c_str(), - new ReceiverThreadDelegate(iap2ea_hdl_, this)); + receiver_thread_delegate_ = new ReceiverThreadDelegate(iap2ea_hdl_, this); + receiver_thread_ = new threads::Thread(thread_name.c_str(), receiver_thread_delegate_); receiver_thread_->start(); controller_->ConnectDone(device_uid_, app_handle_); @@ -83,19 +85,8 @@ TransportAdapter::Error IAP2Connection::SendData(RawMessageSptr message) { } TransportAdapter::Error IAP2Connection::Disconnect() { - TransportAdapter::Error error = TransportAdapter::OK; - receiver_thread_->stop(); - - LOG4CXX_TRACE(logger_, "iAP2: closing connection on protocol " << protocol_name_); - if (iap2_eap_close(iap2ea_hdl_) != -1) { - LOG4CXX_DEBUG(logger_, "iAP2: connection on protocol " << protocol_name_ << " closed"); - } - else { - LOG4CXX_WARN(logger_, "iAP2: could not close connection on protocol " << protocol_name_); - error = TransportAdapter::FAIL; - } - parent_->OnDisconnect(app_handle_); + TransportAdapter::Error error = Close() ? TransportAdapter::OK : TransportAdapter::FAIL; controller_->DisconnectDone(device_uid_, app_handle_); return error; } @@ -109,9 +100,40 @@ void IAP2Connection::ReceiveData() { controller_->DataReceiveDone(device_uid_, app_handle_, message); } else { - LOG4CXX_WARN(logger_, "iAP2: error occured while receiving data on protocol " << protocol_name_); - controller_->DataReceiveFailed(device_uid_, app_handle_, DataReceiveError()); + switch (errno) { + case ECONNRESET: + LOG4CXX_INFO(logger_, "iAP2: protocol " << protocol_name_ << " disconnected"); +// receiver_thread_->stop() cannot be invoked here +// because this method is called from receiver_thread_ +// anyway delegate can be stopped directly + receiver_thread_delegate_->exitThreadMain(); + Close(); + controller_->ConnectionAborted(device_uid_, app_handle_, CommunicationError()); + break; + default: + LOG4CXX_WARN(logger_, "iAP2: error occured while receiving data on protocol " << protocol_name_); + controller_->DataReceiveFailed(device_uid_, app_handle_, DataReceiveError()); + break; + } + } +} + +bool IAP2Connection::Close() { + bool result; + + LOG4CXX_TRACE(logger_, "iAP2: closing connection on protocol " << protocol_name_); + if (iap2_eap_close(iap2ea_hdl_) != -1) { + LOG4CXX_DEBUG(logger_, "iAP2: connection on protocol " << protocol_name_ << " closed"); + result = true; + } + else { + LOG4CXX_WARN(logger_, "iAP2: could not close connection on protocol " << protocol_name_); + result = false; } + + parent_->OnDisconnect(app_handle_); + + return result; } IAP2Connection::ReceiverThreadDelegate::ReceiverThreadDelegate(iap2ea_hdl_t* iap2ea_hdl, |