new command line option -d to disconnect all clients on shutdown of the server (Ticket #161)

This commit is contained in:
Volker Fischer 2020-05-12 22:40:59 +02:00
parent 34cccac29f
commit 599306156d
4 changed files with 82 additions and 73 deletions

View File

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

View File

@ -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"

View File

@ -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<uint8_t> 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

View File

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