void CClient::connect() { if (m_stream != NULL) { return; } if (m_suspended) { m_connectOnResume = true; return; } try { // resolve the server hostname. do this every time we connect // in case we couldn't resolve the address earlier or the address // has changed (which can happen frequently if this is a laptop // being shuttled between various networks). patch by Brent // Priddy. m_serverAddress.resolve(); // m_serverAddress will be null if the hostname address is not reolved if (m_serverAddress.getAddress() != NULL) { // to help users troubleshoot, show server host name (issue: 60) LOG((CLOG_NOTE "connecting to '%s': %s:%i", m_serverAddress.getHostname().c_str(), ARCH->addrToString(m_serverAddress.getAddress()).c_str(), m_serverAddress.getPort())); } // create the socket IDataSocket* socket = m_socketFactory->create(); // filter socket messages, including a packetizing filter m_stream = socket; if (m_streamFilterFactory != NULL) { m_stream = m_streamFilterFactory->create(m_stream, true); } m_stream = new CPacketStreamFilter(m_events, m_stream, true); if (m_crypto.m_mode != kDisabled) { m_cryptoStream = new CCryptoStream( m_events, m_stream, m_crypto, true); m_stream = m_cryptoStream; } // connect LOG((CLOG_DEBUG1 "connecting to server")); setupConnecting(); setupTimer(); socket->connect(m_serverAddress); } catch (XBase& e) { cleanupTimer(); cleanupConnecting(); delete m_stream; m_stream = NULL; LOG((CLOG_DEBUG1 "connection failed")); sendConnectionFailedEvent(e.what()); return; } }
void Client::handleConnectTimeout(const Event&, void*) { cleanupTimer(); cleanupConnecting(); cleanupConnection(); cleanupStream(); LOG((CLOG_DEBUG1 "connection timed out")); sendConnectionFailedEvent("Timed out"); }
void CClient::handleConnectTimeout(const CEvent&, void*) { cleanupTimer(); cleanupConnecting(); cleanupConnection(); delete m_stream; m_stream = NULL; LOG((CLOG_DEBUG1 "connection timed out")); sendConnectionFailedEvent("Timed out"); }
void Client::handleConnectionFailed(const Event& event, void*) { IDataSocket::ConnectionFailedInfo* info = reinterpret_cast<IDataSocket::ConnectionFailedInfo*>(event.getData()); cleanupTimer(); cleanupConnecting(); cleanupStream(); LOG((CLOG_DEBUG1 "connection failed")); sendConnectionFailedEvent(info->m_what.c_str()); delete info; }
void CClient::handleConnected(const CEvent&, void*) { LOG((CLOG_DEBUG1 "connected; wait for hello")); cleanupConnecting(); setupConnection(); // reset clipboard state for (ClipboardID id = 0; id < kClipboardEnd; ++id) { m_ownClipboard[id] = false; m_sentClipboard[id] = false; m_timeClipboard[id] = 0; } }
CClient::~CClient() { EVENTQUEUE->removeHandler(IScreen::getSuspendEvent(), getEventTarget()); EVENTQUEUE->removeHandler(IScreen::getResumeEvent(), getEventTarget()); cleanupTimer(); cleanupScreen(); cleanupConnecting(); cleanupConnection(); delete m_socketFactory; delete m_streamFilterFactory; }
void Client::disconnect(const char* msg) { m_connectOnResume = false; cleanupTimer(); cleanupScreen(); cleanupConnecting(); cleanupConnection(); if (msg != NULL) { sendConnectionFailedEvent(msg); } else { sendEvent(m_events->forClient().disconnected(), NULL); } }
Client::~Client() { if (m_mock) { return; } m_events->removeHandler(m_events->forIScreen().suspend(), getEventTarget()); m_events->removeHandler(m_events->forIScreen().resume(), getEventTarget()); cleanupTimer(); cleanupScreen(); cleanupConnecting(); cleanupConnection(); delete m_socketFactory; }
void CClient::connect() { if (m_stream != NULL) { return; } if (m_suspended) { m_connectOnResume = true; return; } try { // resolve the server hostname. do this every time we connect // in case we couldn't resolve the address earlier or the address // has changed (which can happen frequently if this is a laptop // being shuttled between various networks). patch by Brent // Priddy. m_serverAddress.resolve(); // create the socket IDataSocket* socket = m_socketFactory->create(); // filter socket messages, including a packetizing filter m_stream = socket; if (m_streamFilterFactory != NULL) { m_stream = m_streamFilterFactory->create(m_stream, true); } m_stream = new CPacketStreamFilter(m_stream, true); // connect LOG((CLOG_DEBUG1 "connecting to server")); setupConnecting(); setupTimer(); socket->connect(m_serverAddress); } catch (XBase& e) { cleanupTimer(); cleanupConnecting(); delete m_stream; m_stream = NULL; LOG((CLOG_DEBUG1 "connection failed")); sendConnectionFailedEvent(e.what()); return; } }
CClient::~CClient() { // HACK: can't disable dtor with mocks if (m_mock) return; m_eventQueue.removeHandler(IScreen::getSuspendEvent(), getEventTarget()); m_eventQueue.removeHandler(IScreen::getResumeEvent(), getEventTarget()); cleanupTimer(); cleanupScreen(); cleanupConnecting(); cleanupConnection(); delete m_socketFactory; delete m_streamFilterFactory; }