Repository navigation
Convert host and SRV lookups to async instead of blocking #3986
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
base: main
Are you sure you want to change the base?
Changes from all commits
4bda78d
c3e897a
4c42f34
18fbfa1
156cfed
8687b01
14266e0
1039c7f
13ce6f3
31ac523
1ec14e1
39be89c
f79deed
1a7d0d5
bc1aa0d
d119ccc
863c0d7
488b207
a4ea676
f44aecf
ab23b92
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 |
|---|---|---|
|
|
@@ -93,7 +93,8 @@ CClient::CClient ( const quint16 iPortNumber, | |
| bJitterBufferOK ( true ), | ||
| bMuteMeInPersonalMix ( bNMuteMeInPersonalMix ), | ||
| iServerSockBufNumFrames ( DEF_NET_BUF_SIZE_NUM_BL ), | ||
| bRawAudioIsSupported ( false ) | ||
| bRawAudioIsSupported ( false ), | ||
| iResolverSeq ( 0 ) | ||
| { | ||
| int iOpusError; | ||
|
|
||
|
|
@@ -334,6 +335,15 @@ void CClient::OnNewConnection() | |
| //### TODO: END ###// | ||
| } | ||
|
|
||
| void CClient::OnCLDisconnection ( CHostAddress InetAddr ) | ||
| { | ||
| if ( eConnectionState != CS_RESOLVING && InetAddr == Channel.GetAddress() ) | ||
| { | ||
| // Stop client in case it received a Disconnection request | ||
| Stop(); | ||
| } | ||
| } | ||
|
|
||
| void CClient::OnMuteStateHasChangedReceived ( int iServerChanID, bool bIsMuted ) | ||
| { | ||
| // map iChanID from server channel ID to client channel ID | ||
|
|
@@ -619,25 +629,6 @@ void CClient::SetRemoteChanPan ( const int iId, const float fPan ) | |
| StartTimerGainOrPan(); | ||
| } | ||
|
|
||
| bool CClient::SetServerAddr ( QString strNAddr ) | ||
| { | ||
| CHostAddress HostAddress; | ||
| if ( NetworkUtil::ParseNetworkAddress ( strNAddr, HostAddress, bIPv6Available ) ) | ||
| { | ||
| // apply address to the channel | ||
| Channel.SetAddress ( HostAddress ); | ||
|
|
||
| // By default, set server name to HostAddress. If using the Connect() method, this may be overwritten | ||
| SetConnectedServerName ( HostAddress.toString() ); | ||
|
|
||
| return true; | ||
| } | ||
| else | ||
| { | ||
| return false; // invalid address | ||
| } | ||
| } | ||
|
|
||
| bool CClient::GetAndResetbJitterBufferOKFlag() | ||
| { | ||
| // get the socket buffer put status flag and reset it | ||
|
|
@@ -1150,10 +1141,18 @@ void CClient::Stop() | |
| /// @emit Disconnected | ||
| void CClient::Disconnect() | ||
| { | ||
| ++iResolverSeq; // invalidate any uncompleted resolver requests | ||
|
|
||
| // Key off the connection state, not IsRunning() (which tracks the audio | ||
| // device): the two diverge while connecting and in headless mode, and on | ||
| // SIGTERM we must still send the disconnect message to the server. | ||
| if ( GetConnectionState() != CS_DISCONNECTED ) | ||
| if ( eConnectionState == CS_RESOLVING ) | ||
| { | ||
| // no need to Stop, as we haven't Started, but need to update connection state | ||
| SetConnectionState ( CS_DISCONNECTED ); | ||
| emit Disconnected(); | ||
| } | ||
| else if ( eConnectionState != CS_DISCONNECTED ) | ||
| { | ||
| Stop(); | ||
| } | ||
|
|
@@ -1162,36 +1161,79 @@ void CClient::Disconnect() | |
| /// @method | ||
| /// @brief Connects to strServerAddress. If a connection is currently requested | ||
| /// or established, that connection is terminated first. | ||
| /// @emit Connecting (strServerName) if SetServerAddr was valid. emit happens through Start(). | ||
| /// @emit Connecting (strServerName) if address was valid. emit happens through Start(). | ||
| /// Use to set CClientDlg to show being connected | ||
| /// @emit ConnectingFailed (error) if an error occurred | ||
| /// Use to display error message in CClientDlg | ||
| /// @param strServerAddress - the server address to connect to | ||
| /// @param strServerName - the human readable server name passed to Connecting() | ||
| void CClient::Connect ( const QString& strServerAddress, const QString& strServerName ) | ||
| { | ||
| try | ||
| // disconnect from any current server first so that connecting to a | ||
| // different server while connected behaves as a reconnect | ||
| Disconnect(); | ||
|
|
||
| // note that we are resolving the address | ||
| SetConnectionState ( CS_RESOLVING ); | ||
| emit Resolving ( strServerAddress ); | ||
|
|
||
| const int seq = iResolverSeq; // for capturing the current request | ||
|
|
||
| if ( NetworkUtil::ResolveAddress ( | ||
| strServerAddress, | ||
| bIPv6Available, | ||
| this, | ||
| [this, seq] ( const QHostInfo& info, quint16 port ) { | ||
| // check that the request has not been invalidated | ||
| if ( seq == iResolverSeq ) | ||
| { | ||
| OnHostResolved ( info, port ); // handle result | ||
| } | ||
| }, | ||
| true, // allow hostname resolution | ||
| true ) ) // allow SVR resolution | ||
| { | ||
| SetConnectedServerName ( strServerName ); // set if resolution initiated ok | ||
| } | ||
| else | ||
| { | ||
| // disconnect from any current server first so that connecting to a | ||
| // different server while connected behaves as a reconnect | ||
| Disconnect(); | ||
| SetConnectionState ( CS_DISCONNECTED ); // no longer CS_RESOLVING | ||
| emit ConnectingFailed ( tr ( "Received invalid server address. Please check for typos in the provided server address." ) ); | ||
| } | ||
| } | ||
|
|
||
| // Set server address and connect if valid address was supplied | ||
| if ( SetServerAddr ( strServerAddress ) ) | ||
| { | ||
| SetConnectedServerName ( strServerName ); | ||
| Start(); | ||
| } | ||
| else | ||
| { | ||
| throw CGenErr ( tr ( "Received invalid server address. Please check for typos in the provided server address." ) ); | ||
| } | ||
| void CClient::OnHostResolved ( const QHostInfo& info, quint16 port ) | ||
| { | ||
| if ( info.error() != QHostInfo::NoError ) | ||
| { | ||
| SetConnectionState ( CS_DISCONNECTED ); // no longer CS_RESOLVING | ||
| emit ConnectingFailed ( "Cannot connect: " + info.errorString() ); | ||
|
Member
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. Might want to have a tr() to allow translation? |
||
| return; | ||
| } | ||
| catch ( const CGenErr& generr ) | ||
|
|
||
| for ( const QHostAddress& HostAddr : info.addresses() ) | ||
| { | ||
| Stop(); | ||
| emit ConnectingFailed ( generr.GetErrorText() ); | ||
| // qInfo() << "Resolved network address to" << HostAddr << "for proto" << HostAddr.protocol(); | ||
| if ( HostAddr.protocol() == QAbstractSocket::IPv4Protocol || ( HostAddr.protocol() == QAbstractSocket::IPv6Protocol && bIPv6Available ) ) | ||
|
ann0see marked this conversation as resolved.
Resolved
|
||
| { | ||
| CHostAddress HostAddress ( HostAddr, port ); | ||
| Channel.SetAddress ( HostAddress ); | ||
| // sound device start can throw an exception, which we must catch here | ||
| try | ||
| { | ||
| Start(); | ||
| } | ||
| catch ( const CGenErr& generr ) | ||
|
Member
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 PR, but in general error handling is not great in Jamulus at the moment. So we might want to think about how to handle this in future. This is probably fine-ish (but a CGenErr is probably too general from a theoretical PoV...) |
||
| { | ||
| Stop(); // sets the connection state to CS_DISCONNECTED | ||
| emit ConnectingFailed ( generr.GetErrorText() ); | ||
| } | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| SetConnectionState ( CS_DISCONNECTED ); // no longer CS_RESOLVING | ||
| emit ConnectingFailed ( "Hostname returned no usable addresses" ); | ||
|
Member
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. tr()? Moreover, I don't think this will tell the user enough. In general error messages should tell the user how they can fix the issue. I believe that we document in the style guide how error messages should look like. cc: @gilgongo ? |
||
| } | ||
|
|
||
| /// @method | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.