From f9f04034c9e52aa10b1c52d55cb5b738742d003a Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Tue, 10 Jul 2012 11:23:08 +0000 Subject: [PATCH] fixed: ipc client running on synergyc wasn't sending hello message, and so wasn't getting shutdown message. edits to CIpcClient or CIpcTests weren't really needed, but looks slightly better this way maybe. --- src/lib/ipc/CIpcClient.cpp | 17 +++++++++-------- src/lib/synergy/CClientApp.cpp | 10 ++++++---- src/test/integtests/CIpcTests.cpp | 18 +++++++++++++----- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/lib/ipc/CIpcClient.cpp b/src/lib/ipc/CIpcClient.cpp index 4d494068..faf2d3e0 100644 --- a/src/lib/ipc/CIpcClient.cpp +++ b/src/lib/ipc/CIpcClient.cpp @@ -29,23 +29,21 @@ m_serverAddress(CNetworkAddress(IPC_HOST, IPC_PORT)), m_server(nullptr) { m_serverAddress.resolve(); - - EVENTQUEUE->adoptHandler( - m_socket.getConnectedEvent(), m_socket.getEventTarget(), - new TMethodEventJob( - this, &CIpcClient::handleConnected)); } CIpcClient::~CIpcClient() { - EVENTQUEUE->removeHandler(m_socket.getConnectedEvent(), m_socket.getEventTarget()); - EVENTQUEUE->removeHandler(CIpcServerProxy::getMessageReceivedEvent(), m_server); - delete m_server; + disconnect(); } void CIpcClient::connect() { + EVENTQUEUE->adoptHandler( + IDataSocket::getConnectedEvent(), m_socket.getEventTarget(), + new TMethodEventJob( + this, &CIpcClient::handleConnected)); + m_socket.connect(m_serverAddress); m_server = new CIpcServerProxy(m_socket); @@ -58,6 +56,9 @@ CIpcClient::connect() void CIpcClient::disconnect() { + EVENTQUEUE->removeHandler(IDataSocket::getConnectedEvent(), m_socket.getEventTarget()); + EVENTQUEUE->removeHandler(CIpcServerProxy::getMessageReceivedEvent(), m_server); + m_server->disconnect(); delete m_server; m_server = nullptr; diff --git a/src/lib/synergy/CClientApp.cpp b/src/lib/synergy/CClientApp.cpp index 5d33a40e..1f787485 100644 --- a/src/lib/synergy/CClientApp.cpp +++ b/src/lib/synergy/CClientApp.cpp @@ -528,13 +528,15 @@ CClientApp::mainLoop() // create the event queue CEventQueue eventQueue; - - if (argsBase().m_enableIpc) { - initIpcClient(); - } // start client, etc appUtil().startNode(); + + // init ipc client after node start, since create a new screen wipes out + // the event queue (the screen ctors call adoptBuffer). + if (argsBase().m_enableIpc) { + initIpcClient(); + } // load all available plugins. ARCH->plugin().init(s_clientScreen->getEventTarget()); diff --git a/src/test/integtests/CIpcTests.cpp b/src/test/integtests/CIpcTests.cpp index cf56e8e9..ec0437df 100644 --- a/src/test/integtests/CIpcTests.cpp +++ b/src/test/integtests/CIpcTests.cpp @@ -59,7 +59,9 @@ public: CSocketMultiplexer m_multiplexer; CEventQueue m_events; CEventQueueTimer* m_quitTimeoutTimer; - bool m_connectToServer_clientConnected; + bool m_connectToServer_helloMessageReceived; + bool m_connectToServer_hasClientNode; + CIpcServer* m_connectToServer_server; CString m_sendMessageToServer_receivedString; CString m_sendMessageToClient_receivedString; CIpcClient* m_sendMessageToServer_client; @@ -71,6 +73,7 @@ TEST_F(CIpcTests, connectToServer) { CIpcServer server; server.listen(); + m_connectToServer_server = &server; m_events.adoptHandler( CIpcServer::getMessageReceivedEvent(), &server, @@ -84,8 +87,9 @@ TEST_F(CIpcTests, connectToServer) m_events.loop(); m_events.removeHandler(CIpcServer::getMessageReceivedEvent(), &server); cleanupQuitTimeout(); - - EXPECT_EQ(true, m_connectToServer_clientConnected); + + EXPECT_EQ(true, m_connectToServer_helloMessageReceived); + EXPECT_EQ(true, m_connectToServer_hasClientNode); } TEST_F(CIpcTests, sendMessageToServer) @@ -148,7 +152,9 @@ TEST_F(CIpcTests, sendMessageToClient) CIpcTests::CIpcTests() : m_quitTimeoutTimer(nullptr), -m_connectToServer_clientConnected(false), +m_connectToServer_helloMessageReceived(false), +m_connectToServer_hasClientNode(false), +m_connectToServer_server(nullptr), m_sendMessageToClient_server(nullptr), m_sendMessageToServer_client(nullptr) { @@ -163,7 +169,9 @@ CIpcTests::connectToServer_handleMessageReceived(const CEvent& e, void*) { CIpcMessage* m = static_cast(e.getDataObject()); if (m->m_type == kIpcHello) { - m_connectToServer_clientConnected = true; + m_connectToServer_hasClientNode = + m_connectToServer_server->hasClients(kIpcClientNode); + m_connectToServer_helloMessageReceived = true; raiseQuitEvent(); } }