From 3df75f960123368281f5016d709e747edcdcb94b Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Wed, 24 Aug 2016 16:28:29 +0100 Subject: [PATCH] Conflicts: src/lib/server/ClientListener.cpp --- src/lib/base/EventTypes.cpp | 1 + src/lib/base/EventTypes.h | 11 ++++- src/lib/plugin/ns/SecureSocket.cpp | 1 + src/lib/server/ClientListener.cpp | 67 +++++++++++++++++------------- src/lib/server/ClientListener.h | 1 + 5 files changed, 50 insertions(+), 31 deletions(-) diff --git a/src/lib/base/EventTypes.cpp b/src/lib/base/EventTypes.cpp index 2bb0db1b..2fd9d56d 100644 --- a/src/lib/base/EventTypes.cpp +++ b/src/lib/base/EventTypes.cpp @@ -108,6 +108,7 @@ REGISTER_EVENT(OSXScreen, confirmSleep) // ClientListener // +REGISTER_EVENT(ClientListener, accepted) REGISTER_EVENT(ClientListener, connected) // diff --git a/src/lib/base/EventTypes.h b/src/lib/base/EventTypes.h index 7be8827b..29409624 100644 --- a/src/lib/base/EventTypes.h +++ b/src/lib/base/EventTypes.h @@ -337,11 +337,19 @@ private: class ClientListenerEvents : public EventTypes { public: ClientListenerEvents() : + m_accepted(Event::kUnknown), m_connected(Event::kUnknown) { } //! @name accessors //@{ - + + //! Get accepted event type + /*! + Returns the accepted event type. This is sent whenever a server + accepts a client. + */ + Event::Type accepted(); + //! Get connected event type /*! Returns the connected event type. This is sent whenever a @@ -352,6 +360,7 @@ public: //@} private: + Event::Type m_accepted; Event::Type m_connected; }; diff --git a/src/lib/plugin/ns/SecureSocket.cpp b/src/lib/plugin/ns/SecureSocket.cpp index 979e8616..6e0e8f66 100644 --- a/src/lib/plugin/ns/SecureSocket.cpp +++ b/src/lib/plugin/ns/SecureSocket.cpp @@ -662,6 +662,7 @@ SecureSocket::serviceAccept(ISocketMultiplexerJob* job, // If status > 0, success if (status > 0) { + sendEvent(m_events->forClientListener().accepted()); return newJob(); } diff --git a/src/lib/server/ClientListener.cpp b/src/lib/server/ClientListener.cpp index 078b6013..11c6c8cf 100644 --- a/src/lib/server/ClientListener.cpp +++ b/src/lib/server/ClientListener.cpp @@ -56,6 +56,12 @@ ClientListener::ClientListener(const NetworkAddress& address, m_listen = m_socketFactory->createListen(m_useSecureNetwork); + // setup event handler + m_events->adoptHandler(m_events->forIListenSocket().connecting(), + m_listen, + new TMethodEventJob(this, + &ClientListener::handleClientConnecting)); + // bind listen address LOG((CLOG_DEBUG1 "binding listen socket")); m_listen->bind(address); @@ -71,11 +77,6 @@ ClientListener::ClientListener(const NetworkAddress& address, throw; } LOG((CLOG_DEBUG1 "listening for clients")); - - // setup event handler - m_events->adoptHandler(m_events->forIListenSocket().connecting(), m_listen, - new TMethodEventJob(this, - &ClientListener::handleClientConnecting)); } ClientListener::~ClientListener() @@ -141,41 +142,46 @@ ClientListener::handleClientConnecting(const Event&, void*) if (socket == NULL) { return; } + + m_events->adoptHandler(m_events->forClientListener().accepted(), + stream->getEventTarget(), + new TMethodEventJob(this, + &ClientListener::handleClientAccepted, stream)); + + // When using non SSL, server accepts clients immediately, while SSL + // has to call secure accept which may require retry + if (!m_args.m_enableCrypto) { + m_events->addEvent(Event(m_events->forClientListener().accepted(), + stream)); + } +} +void +ClientListener::handleClientAccepted(const Event&, void* vstream) +{ LOG((CLOG_NOTE "accepted client connection")); - if (m_useSecureNetwork) { - LOG((CLOG_DEBUG2 "attempting sercure Connection")); - while (!socket->isReady()) { - if (socket->isFatal()) { - m_listen->deleteSocket(socket); - return; - } - LOG((CLOG_DEBUG2 "retrying sercure Connection")); - ARCH->sleep(.5f); - } - } - - LOG((CLOG_DEBUG2 "sercure Connection established:%d")); - - synergy::IStream* stream = socket; + synergy::IStream* stream = reinterpret_cast(vstream); + IDataSocket* socket = dynamic_cast(stream); + // filter socket messages, including a packetizing filter - bool adopt = !m_useSecureNetwork; - stream = new PacketStreamFilter(m_events, stream, adopt); - + stream = new PacketStreamFilter(m_events, socket); assert(m_server != NULL); // create proxy for unknown client ClientProxyUnknown* client = new ClientProxyUnknown(stream, 30.0, m_server, m_events); + m_newClients.insert(client); // watch for events from unknown client - m_events->adoptHandler(m_events->forClientProxyUnknown().success(), client, - new TMethodEventJob(this, - &ClientListener::handleUnknownClient, client)); - m_events->adoptHandler(m_events->forClientProxyUnknown().failure(), client, - new TMethodEventJob(this, - &ClientListener::handleUnknownClient, client)); + m_events->adoptHandler(m_events->forClientProxyUnknown().success(), + client, + new TMethodEventJob(this, + &ClientListener::handleUnknownClient, client)); + m_events->adoptHandler(m_events->forClientProxyUnknown().failure(), + client, + new TMethodEventJob(this, + &ClientListener::handleUnknownClient, client)); } void @@ -193,7 +199,8 @@ ClientListener::handleUnknownClient(const Event&, void* vclient) if (client != NULL) { // handshake was successful m_waitingClients.push_back(client); - m_events->addEvent(Event(m_events->forClientListener().connected(), this)); + m_events->addEvent(Event(m_events->forClientListener().connected(), + this)); // watch for client to disconnect while it's in our queue m_events->adoptHandler(m_events->forClientProxy().disconnected(), client, diff --git a/src/lib/server/ClientListener.h b/src/lib/server/ClientListener.h index 7aefe7f4..7674386c 100644 --- a/src/lib/server/ClientListener.h +++ b/src/lib/server/ClientListener.h @@ -69,6 +69,7 @@ public: private: // client connection event handlers void handleClientConnecting(const Event&, void*); + void handleClientAccepted(const Event&, void*); void handleUnknownClient(const Event&, void*); void handleClientDisconnected(const Event&, void*);