Fix bug keeping write and read queue on disconnect 89/33089/3
authorMarcin Niesluchowski <m.niesluchow@samsung.com>
Mon, 5 Jan 2015 11:22:21 +0000 (12:22 +0100)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Fri, 9 Jan 2015 07:26:15 +0000 (08:26 +0100)
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
src/client-async/sockets/SocketClientAsync.h

index 148b13a..7be87d1 100644 (file)
@@ -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
index eaacf84..511221b 100644 (file)
@@ -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