-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connection status issue #2519 #2550
Changes from all commits
3bb34f4
9aeceb0
f9f5e30
24f59e0
0923cff
03a8782
b152344
1299e73
553d98b
a225596
a96660a
6af7e96
4570ec4
7125707
1b17d48
cd7b785
a675833
95a6509
8df0e29
beed54e
648880c
ae07615
2b66414
b88e704
6ea6c19
20fe0b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ CChannel::CChannel ( const bool bNIsServer ) : | |
bIsEnabled ( false ), | ||
bIsServer ( bNIsServer ), | ||
bIsIdentified ( false ), | ||
bDisconnectAndDisable ( false ), | ||
iAudioFrameSizeSamples ( DOUBLE_SYSTEM_FRAME_SIZE_SAMPLES ), | ||
SignalLevelMeter ( false, 0.5 ) // server mode with mono out and faster smoothing | ||
{ | ||
|
@@ -125,7 +126,8 @@ void CChannel::SetEnable ( const bool bNEnStat ) | |
QMutexLocker locker ( &Mutex ); | ||
|
||
// set internal parameter | ||
bIsEnabled = bNEnStat; | ||
bIsEnabled = bNEnStat; | ||
bDisconnectAndDisable = false; | ||
|
||
// The support for the packet sequence number must be reset if the client | ||
// disconnects from a server since we do not yet know if the next server we | ||
|
@@ -506,11 +508,20 @@ void CChannel::Disconnect() | |
// we only have to disconnect the channel if it is actually connected | ||
if ( IsConnected() ) | ||
{ | ||
// for a Client we will block further audio data and disable the channel as soon as disconnected; | ||
bDisconnectAndDisable = !bIsServer; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reasoning to be investigated. |
||
|
||
// set time out counter to a small value > 0 so that the next time a | ||
// received audio block is queried, the disconnection is performed | ||
// (assuming that no audio packet is received in the meantime) | ||
iConTimeOut = 1; // a small number > 0 | ||
} | ||
else if ( !bIsServer ) | ||
{ | ||
bDisconnectAndDisable = false; | ||
bIsEnabled = false; | ||
iConTimeOut = 0; | ||
} | ||
} | ||
|
||
void CChannel::PutProtocolData ( const int iRecCounter, const int iRecID, const CVector<uint8_t>& vecbyMesBodyData, const CHostAddress& RecHostAddr ) | ||
|
@@ -534,7 +545,7 @@ EPutDataStat CChannel::PutAudioData ( const CVector<uint8_t>& vecbyData, const i | |
// Only process audio data if: | ||
// - for client only: the packet comes from the server we want to talk to | ||
// - the channel is enabled | ||
if ( ( bIsServer || ( GetAddress() == RecHostAddr ) ) && IsEnabled() ) | ||
if ( ( bIsServer || ( GetAddress() == RecHostAddr ) ) && IsEnabled() && !bDisconnectAndDisable ) | ||
{ | ||
MutexSocketBuf.lock(); | ||
{ | ||
|
@@ -622,6 +633,12 @@ EGetDataStat CChannel::GetData ( CVector<uint8_t>& vecbyData, const int iNumByte | |
eGetStatus = GS_CHAN_NOW_DISCONNECTED; | ||
iConTimeOut = 0; // make sure we do not have negative values | ||
|
||
if ( bDisconnectAndDisable ) | ||
{ | ||
bDisconnectAndDisable = false; | ||
bIsEnabled = false; | ||
} | ||
|
||
// reset network transport properties | ||
ResetNetworkTransportProperties(); | ||
} | ||
|
@@ -643,6 +660,13 @@ EGetDataStat CChannel::GetData ( CVector<uint8_t>& vecbyData, const int iNumByte | |
{ | ||
// channel is disconnected | ||
eGetStatus = GS_CHAN_NOT_CONNECTED; | ||
|
||
if ( bDisconnectAndDisable ) | ||
{ | ||
bDisconnectAndDisable = false; | ||
bIsEnabled = false; | ||
iConTimeOut = 0; | ||
} | ||
} | ||
} | ||
MutexSocketBuf.unlock(); | ||
|
@@ -652,7 +676,6 @@ EGetDataStat CChannel::GetData ( CVector<uint8_t>& vecbyData, const int iNumByte | |
{ | ||
// reset the protocol | ||
Protocol.Reset(); | ||
|
||
// emit message | ||
emit Disconnected(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,7 +76,7 @@ class CChannel : public QObject | |
|
||
void PrepAndSendPacket ( CHighPrioSocket* pSocket, const CVector<uint8_t>& vecbyNPacket, const int iNPacketLen ); | ||
|
||
void ResetTimeOutCounter() { iConTimeOut = iConTimeOutStartVal; } | ||
void ResetTimeOutCounter() { iConTimeOut = bDisconnectAndDisable ? 1 : iConTimeOutStartVal; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How often do we use short hand if in the source? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You mean conditional assignment ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I usually think it makes code less readable ;-). But in this case I think it's ok - but that depends on if this is used elsewhere too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where's it's a simple "truth" test to pick between two values based on another value, it's okay, in general, I'd say. (I don't think Volker was keen on it.) Anything else (e.g. an expression getting evaluated as any part of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be investigated. May need comment. |
||
bool IsConnected() const { return iConTimeOut > 0; } | ||
void Disconnect(); | ||
|
||
|
@@ -216,6 +216,7 @@ void CreateReqChannelLevelListMes() { Protocol.CreateReqChannelLevelListMes(); } | |
bool bIsEnabled; | ||
bool bIsServer; | ||
bool bIsIdentified; | ||
bool bDisconnectAndDisable; | ||
|
||
int iNetwFrameSizeFact; | ||
int iNetwFrameSize; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,8 +140,8 @@ void CChatDlg::OnAnchorClicked ( const QUrl& Url ) | |
// only allow http(s) URLs to be opened in an external browser | ||
if ( Url.scheme() == QLatin1String ( "https" ) || Url.scheme() == QLatin1String ( "http" ) ) | ||
{ | ||
if ( QMessageBox::question ( this, | ||
APP_NAME, | ||
if ( QMessageBox::question ( CMsgBoxes::MainForm(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not part of this issue. In recreation -> don't include |
||
CMsgBoxes::MainFormName(), | ||
tr ( "Do you want to open the link '%1' in your browser?" ).arg ( "<b>" + Url.toString() + "</b>" ), | ||
QMessageBox::Yes | QMessageBox::No ) == QMessageBox::Yes ) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,6 @@ | |
/* Implementation *************************************************************/ | ||
CClient::CClient ( const quint16 iPortNumber, | ||
const quint16 iQosNumber, | ||
const QString& strConnOnStartupAddress, | ||
const QString& strMIDISetup, | ||
const bool bNoAutoJackConnect, | ||
const QString& strNClientName, | ||
|
@@ -181,13 +180,6 @@ CClient::CClient ( const quint16 iPortNumber, | |
// start the socket (it is important to start the socket after all | ||
// initializations and connections) | ||
Socket.Start(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In depth code review needed to understand changes. |
||
// do an immediate start if a server address is given | ||
if ( !strConnOnStartupAddress.isEmpty() ) | ||
{ | ||
SetServerAddr ( strConnOnStartupAddress ); | ||
Start(); | ||
} | ||
} | ||
|
||
CClient::~CClient() | ||
|
@@ -298,7 +290,7 @@ void CClient::CreateServerJitterBufferMessage() | |
void CClient::OnCLPingReceived ( CHostAddress InetAddr, int iMs ) | ||
{ | ||
// make sure we are running and the server address is correct | ||
if ( IsRunning() && ( InetAddr == Channel.GetAddress() ) ) | ||
if ( Channel.IsEnabled() && ( InetAddr == Channel.GetAddress() ) ) | ||
{ | ||
// take care of wrap arounds (if wrapping, do not use result) | ||
const int iCurDiff = EvaluatePingMessage ( iMs ); | ||
|
@@ -435,22 +427,6 @@ void CClient::StartDelayTimer() | |
} | ||
} | ||
|
||
bool CClient::SetServerAddr ( QString strNAddr ) | ||
{ | ||
CHostAddress HostAddress; | ||
if ( NetworkUtil().ParseNetworkAddress ( strNAddr, HostAddress, bEnableIPv6 ) ) | ||
{ | ||
// apply address to the channel | ||
Channel.SetAddress ( HostAddress ); | ||
|
||
return true; | ||
} | ||
else | ||
{ | ||
return false; // invalid address | ||
} | ||
} | ||
|
||
bool CClient::GetAndResetbJitterBufferOKFlag() | ||
{ | ||
// get the socket buffer put status flag and reset it | ||
|
@@ -586,9 +562,12 @@ QString CClient::SetSndCrdDev ( const QString strNewDev ) | |
// in case of an error inform the GUI about it | ||
if ( !strError.isEmpty() ) | ||
{ | ||
emit SoundDeviceChanged ( strError ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Investigate if this is related. |
||
QMessageBox::critical ( 0, APP_NAME, strError ); | ||
Disconnect(); | ||
} | ||
|
||
emit SoundDeviceChanged(); | ||
|
||
return strError; | ||
} | ||
|
||
|
@@ -715,8 +694,13 @@ void CClient::OnSndCrdReinitRequest ( int iSndCrdResetType ) | |
} | ||
MutexDriverReinit.unlock(); | ||
|
||
if ( !strError.isEmpty() ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Investigate if related |
||
{ | ||
QMessageBox::critical ( 0, APP_NAME, strError ); | ||
} | ||
|
||
// inform GUI about the sound card device change | ||
emit SoundDeviceChanged ( strError ); | ||
emit SoundDeviceChanged(); | ||
} | ||
|
||
void CClient::OnHandledSignal ( int sigNum ) | ||
|
@@ -731,10 +715,7 @@ void CClient::OnHandledSignal ( int sigNum ) | |
case SIGINT: | ||
case SIGTERM: | ||
// if connected, terminate connection (needed for headless mode) | ||
if ( IsRunning() ) | ||
{ | ||
Stop(); | ||
} | ||
Disconnect(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check code validity. Semantic change? Add preconditions to function if needed. |
||
|
||
// this should trigger OnAboutToQuit | ||
QCoreApplication::instance()->exit(); | ||
|
@@ -819,50 +800,89 @@ void CClient::OnClientIDReceived ( int iChanID ) | |
emit ClientIDReceived ( iChanID ); | ||
} | ||
|
||
void CClient::Start() | ||
bool CClient::Connect ( QString strServerAddress, QString strServerName ) | ||
{ | ||
// init object | ||
Init(); | ||
if ( !Channel.IsEnabled() ) | ||
{ | ||
CHostAddress HostAddress; | ||
|
||
if ( NetworkUtil().ParseNetworkAddress ( strServerAddress, HostAddress, bEnableIPv6 ) ) | ||
{ | ||
// init object | ||
Init(); | ||
|
||
// apply address to the channel | ||
Channel.SetAddress ( HostAddress ); | ||
|
||
// enable channel | ||
Channel.SetEnable ( true ); | ||
// enable channel | ||
Channel.SetEnable ( true ); | ||
|
||
// start audio interface | ||
Sound.Start(); | ||
// start audio interface | ||
Sound.Start(); | ||
|
||
// Notify ClientDlg | ||
emit Connecting ( strServerName ); | ||
|
||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
void CClient::Stop() | ||
bool CClient::Disconnect() | ||
{ | ||
// stop audio interface | ||
Sound.Stop(); | ||
|
||
// disable channel | ||
Channel.SetEnable ( false ); | ||
|
||
// wait for approx. 100 ms to make sure no audio packet is still in the | ||
// network queue causing the channel to be reconnected right after having | ||
// received the disconnect message (seems not to gain much, disconnect is | ||
// still not working reliably) | ||
QTime DieTime = QTime::currentTime().addMSecs ( 100 ); | ||
while ( QTime::currentTime() < DieTime ) | ||
if ( Channel.IsEnabled() ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do manual diff comparison to detect changes. |
||
{ | ||
// exclude user input events because if we use AllEvents, it happens | ||
// that if the user initiates a connection and disconnection quickly | ||
// (e.g. quickly pressing enter five times), the software can get into | ||
// an unknown state | ||
QCoreApplication::processEvents ( QEventLoop::ExcludeUserInputEvents, 100 ); | ||
// start disconnection | ||
Channel.Disconnect(); | ||
|
||
// Channel.Disconnect() should now automatically disable Channel as soon as disconnected. | ||
// Note that this only works if Sound is Active ! | ||
|
||
QTime DieTime = QTime::currentTime().addMSecs ( 500 ); | ||
while ( ( QTime::currentTime() < DieTime ) && Channel.IsEnabled() ) | ||
{ | ||
// exclude user input events because if we use AllEvents, it happens | ||
// that if the user initiates a connection and disconnection quickly | ||
// (e.g. quickly pressing enter five times), the software can get into | ||
// an unknown state | ||
QCoreApplication::processEvents ( QEventLoop::ExcludeUserInputEvents, 100 ); | ||
} | ||
|
||
// Now stop the audio interface | ||
Sound.Stop(); | ||
|
||
// in case we timed out, log warning and make sure Channel is disabled | ||
if ( Channel.IsEnabled() ) | ||
{ | ||
Channel.SetEnable ( false ); | ||
} | ||
|
||
// Send disconnect message to server (Since we disable our protocol | ||
// receive mechanism with the next command, we do not evaluate any | ||
// respond from the server, therefore we just hope that the message | ||
// gets its way to the server, if not, the old behaviour time-out | ||
// disconnects the connection anyway). | ||
ConnLessProtocol.CreateCLDisconnection ( Channel.GetAddress() ); | ||
|
||
// reset current signal level and LEDs | ||
bJitterBufferOK = true; | ||
SignalLevelMeter.Reset(); | ||
|
||
emit Disconnected(); | ||
|
||
return true; | ||
} | ||
else | ||
{ | ||
// make sure sound is stopped too | ||
Sound.Stop(); | ||
|
||
// Send disconnect message to server (Since we disable our protocol | ||
// receive mechanism with the next command, we do not evaluate any | ||
// respond from the server, therefore we just hope that the message | ||
// gets its way to the server, if not, the old behaviour time-out | ||
// disconnects the connection anyway). | ||
ConnLessProtocol.CreateCLDisconnection ( Channel.GetAddress() ); | ||
emit Disconnected(); | ||
|
||
// reset current signal level and LEDs | ||
bJitterBufferOK = true; | ||
SignalLevelMeter.Reset(); | ||
return false; | ||
} | ||
} | ||
|
||
void CClient::Init() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No changes to be made