From 5999e3ccaad8da0b7c70240714cbe168905f0437 Mon Sep 17 00:00:00 2001 From: Marcin Niesluchowski Date: Mon, 5 Jan 2015 12:22:21 +0100 Subject: [PATCH] Fix bug keeping write and read queue on disconnect Read and write binary queues are not cleared in asynchronous client after disconnect happens. Add clearing function in connect() and completeConnection() functions of SocketClientAsync class, when connection state changes. Change-Id: I18f5d13a1a21d0b99ebe456bfafd4487df9c1767 --- src/client-async/sockets/SocketClientAsync.cpp | 18 +++++++++++++++--- src/client-async/sockets/SocketClientAsync.h | 4 +++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/client-async/sockets/SocketClientAsync.cpp b/src/client-async/sockets/SocketClientAsync.cpp index 148b13a..7be87d1 100644 --- a/src/client-async/sockets/SocketClientAsync.cpp +++ b/src/client-async/sockets/SocketClientAsync.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,11 +35,17 @@ SocketClientAsync::SocketClientAsync(const std::string &socketPath, ProtocolPtr } Socket::ConnectionStatus SocketClientAsync::connect(void) { - return m_socket.connect(); + Socket::ConnectionStatus status = m_socket.connect(); + if (status != Socket::ConnectionStatus::ALREADY_CONNECTED) + clear(); + return status; } Socket::ConnectionStatus SocketClientAsync::completeConnection(void) { - return m_socket.completeConnection(); + Socket::ConnectionStatus status = m_socket.completeConnection(); + if (status == Socket::ConnectionStatus::CONNECTION_FAILED) + clear(); + return status; } int SocketClientAsync::getSockFd(void) { @@ -71,4 +77,10 @@ ResponsePtr SocketClientAsync::getResponse(void) { return m_protocol->extractResponseFromBuffer(m_readQueue); } +void SocketClientAsync::clear(void) +{ + m_readQueue->clear(); + m_writeQueue->clear(); +} + } // namespace Cynara diff --git a/src/client-async/sockets/SocketClientAsync.h b/src/client-async/sockets/SocketClientAsync.h index eaacf84..511221b 100644 --- a/src/client-async/sockets/SocketClientAsync.h +++ b/src/client-async/sockets/SocketClientAsync.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,6 +58,8 @@ private: ProtocolPtr m_protocol; BinaryQueuePtr m_readQueue; BinaryQueuePtr m_writeQueue; + + void clear(void); }; } // namespace Cynara -- 2.7.4