From fc600efdfe8639f3625a6a902be96ce5ba9c75b7 Mon Sep 17 00:00:00 2001 From: Xinyu Hou Date: Wed, 29 Jul 2015 02:01:39 +0100 Subject: [PATCH] Restarted process from GUI in desktop mode #4901 --- 1.patch | 96 ++++++++++++++++++++++++++++++++++++++ src/gui/src/MainWindow.cpp | 25 +++++++++- src/gui/src/MainWindow.h | 9 +++- 3 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 1.patch diff --git a/1.patch b/1.patch new file mode 100644 index 00000000..8e46b046 --- /dev/null +++ b/1.patch @@ -0,0 +1,96 @@ +diff --git a/src/lib/plugin/ns/SecureSocket.cpp b/src/lib/plugin/ns/SecureSocket.cpp +index 40c3f21..e02ba9d 100644 +--- a/src/lib/plugin/ns/SecureSocket.cpp ++++ b/src/lib/plugin/ns/SecureSocket.cpp +@@ -35,12 +35,9 @@ + // + + #define MAX_ERROR_SIZE 65535 +- +-enum { +- // this limit seems extremely high, but mac client seem to generate around +- // 50,000 errors before they establish a connection (wtf?) +- kMaxRetryCount = 100000 +-}; ++// RETRY_DELAY * MAX_RETRY = 10s ++#define MAX_RETRY 1000 ++#define RETRY_DELAY 0.01f + + enum { + kMsgSize = 128 +@@ -61,8 +58,7 @@ SecureSocket::SecureSocket( + SocketMultiplexer* socketMultiplexer) : + TCPSocket(events, socketMultiplexer), + m_secureReady(false), +- m_fatal(false), +- m_maxRetry(kMaxRetryCount) ++ m_fatal(false) + { + } + +@@ -72,8 +68,7 @@ SecureSocket::SecureSocket( + ArchSocket socket) : + TCPSocket(events, socketMultiplexer, socket), + m_secureReady(false), +- m_fatal(false), +- m_maxRetry(kMaxRetryCount) ++ m_fatal(false) + { + } + +@@ -295,8 +290,7 @@ SecureSocket::secureAccept(int socket) + + if (isFatal()) { + // tell user and sleep so the socket isn't hammered. +- LOG((CLOG_ERR "failed to accept secure socket")); +- LOG((CLOG_INFO "client connection may not be secure")); ++ LOG((CLOG_WARN "failed to accept secure socket")); + m_secureReady = false; + ARCH->sleep(1); + retry = 0; +@@ -318,6 +312,7 @@ SecureSocket::secureAccept(int socket) + if (retry > 0) { + LOG((CLOG_DEBUG2 "retry accepting secure socket")); + m_secureReady = false; ++ ARCH->sleep(RETRY_DELAY); + return 0; + } + +@@ -351,6 +346,7 @@ SecureSocket::secureConnect(int socket) + if (retry > 0) { + LOG((CLOG_DEBUG2 "retry connect secure socket")); + m_secureReady = false; ++ ARCH->sleep(RETRY_DELAY); + return 0; + } + +@@ -475,8 +471,8 @@ SecureSocket::checkResult(int status, int& retry) + } + + // If the retry max would exceed the allowed, treat it as a fatal error +- if (retry > maxRetry()) { +- LOG((CLOG_ERR "passive ssl error limit exceeded: %d", retry)); ++ if (retry > MAX_RETRY) { ++ LOG((CLOG_DEBUG "retry exceeded %d sec", RETRY_DELAY * MAX_RETRY)); + isFatal(true); + } + +diff --git a/src/lib/plugin/ns/SecureSocket.h b/src/lib/plugin/ns/SecureSocket.h +index 0c0f3b1..871e1e4 100644 +--- a/src/lib/plugin/ns/SecureSocket.h ++++ b/src/lib/plugin/ns/SecureSocket.h +@@ -52,8 +52,6 @@ public: + int secureWrite(const void* buffer, int size, int& wrote); + void initSsl(bool server); + bool loadCertificates(String& CertFile); +- void maxRetry(int limit) { m_maxRetry = limit; }; +- int maxRetry() const { return m_maxRetry; }; + + private: + // SSL +@@ -87,5 +85,4 @@ private: + Ssl* m_ssl; + bool m_secureReady; + bool m_fatal; +- int m_maxRetry; + }; diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index d7488b59..162320b6 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -96,7 +96,8 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) : m_pCancelButton(NULL), m_SuppressAutoConfigWarning(false), m_BonjourInstall(NULL), - m_SuppressEmptyServerWarning(false) + m_SuppressEmptyServerWarning(false), + m_ExpectedRunningState(kStopped) { setupUi(this); @@ -142,6 +143,7 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) : MainWindow::~MainWindow() { if (appConfig().processMode() == Desktop) { + m_ExpectedRunningState = kStopped; stopDesktop(); } @@ -777,6 +779,15 @@ void MainWindow::synergyFinished(int exitCode, QProcess::ExitStatus) QMessageBox::critical(this, tr("Synergy terminated with an error"), QString(tr("Synergy terminated unexpectedly with an exit code of %1.

Please see the log output for details.")).arg(exitCode)); stopSynergy(); } + + if (appConfig().processMode() == Desktop) { + if (m_ExpectedRunningState == kStarted) { + stopSynergy(); + delay(1); + startSynergy(); + } + } + #else Q_UNUSED(exitCode); #endif @@ -823,6 +834,7 @@ void MainWindow::setSynergyState(qSynergyState state) } setStatus(tr("Synergy is running.")); + m_ExpectedRunningState = kStarted; break; } @@ -1338,3 +1350,14 @@ void MainWindow::delay(unsigned int s) QCoreApplication::processEvents(QEventLoop::AllEvents, 100); } } + +void MainWindow::on_m_pButtonToggleStart_clicked() +{ + if (m_SynergyState != synergyConnected) { + m_ExpectedRunningState = kStarted; + } + else { + m_ExpectedRunningState = kStopped; + } + +} diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index 3f57386b..94c20c6d 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -85,6 +85,11 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase Info }; + enum qRuningState { + kStarted, + kStopped + }; + public: MainWindow(QSettings& settings, AppConfig& appConfig); ~MainWindow(); @@ -138,7 +143,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase protected: QSettings& settings() { return m_Settings; } AppConfig& appConfig() { return m_AppConfig; } - QProcess*& synergyProcess() { return m_pSynergy; } + QProcess* synergyProcess() { return m_pSynergy; } void setSynergyProcess(QProcess* p) { m_pSynergy = p; } void initConnections(); void createMenuBar(); @@ -200,12 +205,14 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase bool m_SuppressAutoConfigWarning; CommandProcess* m_BonjourInstall; bool m_SuppressEmptyServerWarning; + qRuningState m_ExpectedRunningState; private slots: void on_m_pCheckBoxAutoConfig_toggled(bool checked); void on_m_pComboServerList_currentIndexChanged(QString ); void on_m_pButtonApply_clicked(); void installBonjour(); + void on_m_pButtonToggleStart_clicked(); }; #endif