Conflicts:

src/lib/server/ClientListener.cpp
This commit is contained in:
Jerry (Xinyu Hou) 2016-08-24 16:28:29 +01:00 committed by Andrew Nelless
parent e1be67cfb6
commit 3df75f9601
5 changed files with 50 additions and 31 deletions

View File

@ -108,6 +108,7 @@ REGISTER_EVENT(OSXScreen, confirmSleep)
// ClientListener
//
REGISTER_EVENT(ClientListener, accepted)
REGISTER_EVENT(ClientListener, connected)
//

View File

@ -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;
};

View File

@ -662,6 +662,7 @@ SecureSocket::serviceAccept(ISocketMultiplexerJob* job,
// If status > 0, success
if (status > 0) {
sendEvent(m_events->forClientListener().accepted());
return newJob();
}

View File

@ -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<ClientListener>(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<ClientListener>(this,
&ClientListener::handleClientConnecting));
}
ClientListener::~ClientListener()
@ -142,38 +143,43 @@ ClientListener::handleClientConnecting(const Event&, void*)
return;
}
m_events->adoptHandler(m_events->forClientListener().accepted(),
stream->getEventTarget(),
new TMethodEventJob<ClientListener>(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);
}
}
synergy::IStream* stream = reinterpret_cast<synergy::IStream*>(vstream);
IDataSocket* socket = dynamic_cast<IDataSocket*>(stream);
LOG((CLOG_DEBUG2 "sercure Connection established:%d"));
synergy::IStream* stream = socket;
// 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,
m_events->adoptHandler(m_events->forClientProxyUnknown().success(),
client,
new TMethodEventJob<ClientListener>(this,
&ClientListener::handleUnknownClient, client));
m_events->adoptHandler(m_events->forClientProxyUnknown().failure(), client,
m_events->adoptHandler(m_events->forClientProxyUnknown().failure(),
client,
new TMethodEventJob<ClientListener>(this,
&ClientListener::handleUnknownClient, client));
}
@ -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,

View File

@ -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*);