From 599306156d81d80ae3457e2e4c441df28a0b9ab7 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Tue, 12 May 2020 22:40:59 +0200 Subject: [PATCH] new command line option -d to disconnect all clients on shutdown of the server (Ticket #161) --- ChangeLog | 2 ++ src/main.cpp | 85 +++++++++++++++++++++++++------------------------- src/server.cpp | 64 ++++++++++++++++++++----------------- src/server.h | 4 +-- 4 files changed, 82 insertions(+), 73 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2475f32c..fd172635 100644 --- a/ChangeLog +++ b/ChangeLog @@ -21,6 +21,8 @@ - new design for the About dialog (Ticket #189) +- new command line option -d to disconnect all clients on shutdown of the server (Ticket #161) + - bug fix: for mono capture jack audio interface Jamulus complains it cannot make connections (Ticket #137) diff --git a/src/main.cpp b/src/main.cpp index fa615518..385b5fef 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,36 +51,36 @@ int main ( int argc, char** argv ) // arguments #if defined( SERVER_BUNDLE ) && ( defined( __APPLE__ ) || defined( __MACOSX ) ) // if we are on MacOS and we are building a server bundle, starts Jamulus in server mode - bool bIsClient = false; + bool bIsClient = false; #else - bool bIsClient = true; + bool bIsClient = true; #endif - bool bUseGUI = true; - bool bStartMinimized = false; - bool bShowComplRegConnList = false; - bool bDisconnectAllClients = false; - bool bUseDoubleSystemFrameSize = true; // default is 128 samples frame size - bool bShowAnalyzerConsole = false; - bool bCentServPingServerInList = false; - bool bNoAutoJackConnect = false; - bool bUseTranslation = true; - bool bCustomPortNumberGiven = false; - int iNumServerChannels = DEFAULT_USED_NUM_CHANNELS; - int iMaxDaysHistory = DEFAULT_DAYS_HISTORY; - int iCtrlMIDIChannel = INVALID_MIDI_CH; - quint16 iPortNumber = LLCON_DEFAULT_PORT_NUMBER; - ELicenceType eLicenceType = LT_NO_LICENCE; - QString strConnOnStartupAddress = ""; - QString strIniFileName = ""; - QString strHTMLStatusFileName = ""; - QString strServerName = ""; - QString strLoggingFileName = ""; - QString strHistoryFileName = ""; - QString strRecordingDirName = ""; - QString strCentralServer = ""; - QString strServerInfo = ""; - QString strWelcomeMessage = ""; - QString strClientName = APP_NAME; + bool bUseGUI = true; + bool bStartMinimized = false; + bool bShowComplRegConnList = false; + bool bDisconnectAllClientsOnQuit = false; + bool bUseDoubleSystemFrameSize = true; // default is 128 samples frame size + bool bShowAnalyzerConsole = false; + bool bCentServPingServerInList = false; + bool bNoAutoJackConnect = false; + bool bUseTranslation = true; + bool bCustomPortNumberGiven = false; + int iNumServerChannels = DEFAULT_USED_NUM_CHANNELS; + int iMaxDaysHistory = DEFAULT_DAYS_HISTORY; + int iCtrlMIDIChannel = INVALID_MIDI_CH; + quint16 iPortNumber = LLCON_DEFAULT_PORT_NUMBER; + ELicenceType eLicenceType = LT_NO_LICENCE; + QString strConnOnStartupAddress = ""; + QString strIniFileName = ""; + QString strHTMLStatusFileName = ""; + QString strServerName = ""; + QString strLoggingFileName = ""; + QString strHistoryFileName = ""; + QString strRecordingDirName = ""; + QString strCentralServer = ""; + QString strServerInfo = ""; + QString strWelcomeMessage = ""; + QString strClientName = APP_NAME; // QT docu: argv()[0] is the program name, argv()[1] is the first // argument and argv()[argc()-1] is the last argument. @@ -200,6 +200,18 @@ int main ( int argc, char** argv ) } + // Disconnect all clients on quit -------------------------------------- + if ( GetFlagArgument ( argv, + i, + "-d", + "--discononquit" ) ) + { + bDisconnectAllClientsOnQuit = true; + tsConsole << "- disconnect all clients on quit" << endl; + continue; + } + + // Disabling auto Jack connections ------------------------------------- if ( GetFlagArgument ( argv, i, @@ -239,20 +251,6 @@ int main ( int argc, char** argv ) } - // Disconnect all clients (emergency mode) ----------------------------- - // Undocumented debugging command line argument: Needed to disconnect - // an unwanted client. - if ( GetFlagArgument ( argv, - i, - "--disconnectall", // no short form - "--disconnectall" ) ) - { - bDisconnectAllClients = true; - tsConsole << "- disconnect all clients" << endl; - continue; - } - - // Show analyzer console ----------------------------------------------- // Undocumented debugging command line argument: Show the analyzer // console to debug network buffer properties. @@ -626,7 +624,7 @@ int main ( int argc, char** argv ) strWelcomeMessage, strRecordingDirName, bCentServPingServerInList, - bDisconnectAllClients, + bDisconnectAllClientsOnQuit, bUseDoubleSystemFrameSize, eLicenceType ); if ( bUseGUI ) @@ -704,6 +702,7 @@ QString UsageArguments ( char **argv ) " -v, --version output version information and exit\n" "\nServer only:\n" " -a, --servername server name, required for HTML status\n" + " -d, --discononquit disconnect all clients on quit\n" " -D, --histdays number of days of history to display\n" " -e, --centralserver address of the central server\n" " -F, --fastupdate use 64 samples frame size mode\n" diff --git a/src/server.cpp b/src/server.cpp index 40e2e63b..a7d593c4 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -231,28 +231,28 @@ CServer::CServer ( const int iNewMaxNumChan, const QString& strNewWelcomeMessage, const QString& strRecordingDirName, const bool bNCentServPingServerInList, - const bool bNDisconnectAllClients, + const bool bNDisconnectAllClientsOnQuit, const bool bNUseDoubleSystemFrameSize, const ELicenceType eNLicenceType ) : - bUseDoubleSystemFrameSize ( bNUseDoubleSystemFrameSize ), - iMaxNumChannels ( iNewMaxNumChan ), - Socket ( this, iPortNumber ), - Logging ( iMaxDaysHistory ), - JamRecorder ( strRecordingDirName ), - bEnableRecording ( !strRecordingDirName.isEmpty() ), - bWriteStatusHTMLFile ( false ), - HighPrecisionTimer ( bNUseDoubleSystemFrameSize ), - ServerListManager ( iPortNumber, - strCentralServer, - strServerInfo, - iNewMaxNumChan, - bNCentServPingServerInList, - &ConnLessProtocol ), - bAutoRunMinimized ( false ), - strWelcomeMessage ( strNewWelcomeMessage ), - eLicenceType ( eNLicenceType ), - bDisconnectAllClients ( bNDisconnectAllClients ), - pSignalHandler ( CSignalHandler::getSingletonP() ) + bUseDoubleSystemFrameSize ( bNUseDoubleSystemFrameSize ), + iMaxNumChannels ( iNewMaxNumChan ), + Socket ( this, iPortNumber ), + Logging ( iMaxDaysHistory ), + JamRecorder ( strRecordingDirName ), + bEnableRecording ( !strRecordingDirName.isEmpty() ), + bWriteStatusHTMLFile ( false ), + HighPrecisionTimer ( bNUseDoubleSystemFrameSize ), + ServerListManager ( iPortNumber, + strCentralServer, + strServerInfo, + iNewMaxNumChan, + bNCentServPingServerInList, + &ConnLessProtocol ), + bAutoRunMinimized ( false ), + strWelcomeMessage ( strNewWelcomeMessage ), + eLicenceType ( eNLicenceType ), + bDisconnectAllClientsOnQuit ( bNDisconnectAllClientsOnQuit ), + pSignalHandler ( CSignalHandler::getSingletonP() ) { int iOpusError; int i; @@ -810,14 +810,6 @@ void CServer::SendProtMessage ( int iChID, CVector vecMessage ) void CServer::OnNewConnection ( int iChID, CHostAddress RecHostAddr ) { - // in the special case that all clients shall be disconnected, just send the - // disconnect message and leave this function - if ( bDisconnectAllClients ) - { - ConnLessProtocol.CreateCLDisconnection ( RecHostAddr ); - return; - } - // on a new connection we query the network transport properties for the // audio packets (to use the correct network block size and audio // compression properties, etc.) @@ -918,6 +910,22 @@ void CServer::OnCLDisconnection ( CHostAddress InetAddr ) void CServer::OnAboutToQuit() { + // if enabled, disconnect all clients on quit + if ( bDisconnectAllClientsOnQuit ) + { + Mutex.lock(); + { + for ( int i = 0; i < iMaxNumChannels; i++ ) + { + if ( vecChannels[i].IsConnected() ) + { + ConnLessProtocol.CreateCLDisconnection ( vecChannels[i].GetAddress() ); + } + } + } + Mutex.unlock(); // release mutex + } + Stop(); // if server was registered at the central server, unregister on shutdown diff --git a/src/server.h b/src/server.h index d68cac38..7cc50b4e 100755 --- a/src/server.h +++ b/src/server.h @@ -178,7 +178,7 @@ public: const QString& strNewWelcomeMessage, const QString& strRecordingDirName, const bool bNCentServPingServerInList, - const bool bNDisconnectAllClients, + const bool bNDisconnectAllClientsOnQuit, const bool bNUseDoubleSystemFrameSize, const ELicenceType eNLicenceType ); @@ -369,7 +369,7 @@ protected: // messaging QString strWelcomeMessage; ELicenceType eLicenceType; - bool bDisconnectAllClients; + bool bDisconnectAllClientsOnQuit; CSignalHandler* pSignalHandler;