[Interest] Bearer management on Linux with NetworkManager and switching between different connection profiles

Aaron McCarthy mccarthy.aaron at gmail.com
Fri Jan 3 11:38:27 CET 2014


Hi,

On Thu, 26 Dec 2013 13:00:30 Jan Kundrát wrote:
> my application uses QSslSockets for communicating with an IMAP server. On
> Linux with NetworkManager, the network connectivity stops working after
> switching between the wired Ethernet and WiFi connections; I have to
> manually disconnect and reconnect from within the application.
> 
> I've tried to follow the steps at [1], but the QNetworkSession instance I
> create using the default configuration does not ever emit the
> preferredConfigurationChanged signal. Indeed, the networkmanager bearer
> plugin does not appear to contain any reference to that signal. This is
> expected, I guess, because the manager's capabilities() returns
> CanStartAndStopInterfaces | ForcedRoaming.

The preferredConfigurationChanged() signal is only emitted from a 
QNetworkSession based on a service network configuration. The network manager 
backend does not support service network configurations, hence, this signal 
will never be emitted.

> The problem I'm facing is that
> there is no clear signal to connect to telling me "hey, please reconnect
> now", though.

The QNetworkConfigurationManager::onlineStateChanged() signal can be used for 
this.

> When I start the application, both eth0 and wlan0 are available. The
> QNetworkConfigurationManager::defaultConfiguration returns "eth0", which is
> correct. I therefore create a QNetworkSession based on this default
> configuration, and get back the opened() signal. So far, so good.
> 
> Upon unplugging the Ethernet cable, the QNetworkSession emits closed() and
> stateChanged(NotAvailable). At that point, the configuration manager emits
> configurationChanged() for the wired, "eth0" configuration. If I ask for
> manager's default configuration from within the slot connected to
> configurationChanged, I now get "wlan0". It seems that the only thing I can
> do at that point is to close the old QNetworkSession, replace it with the
> new one and reconnect. There is no documentation about that, AFAIK.

This is the behaviour described by the ForcedRoaming capability of the manger. 
Even though you have a network session open the system is free to forcibly 
close it. Thought in this case the application doesn't have a choice either 
way as you pulled the cable. The application needs to recover.

> I find this API rather strange to work with. What I would appreciate is a
> signal telling me "hey, the platform decided that you have to reconnect, do
> it now". A simple pair of
> QNetworkConfigurationManager::onlineStateChanged() flapping between false
> and true would be enough. There is also no way of announcing that the
> default configuration has changed; the only workaround I was able to come
> up with involves comparing the old and new QNetworkConfiguration instances
> within a slot connected to the manager's configurationChanged, which looks
> ugly, IMHO.

>From what I understand of your usecase you do not need to both with network 
sessions, the system is bringing up the best interface for you. In which case 
just listen to the QNetworkConfigurationManager::onlineStateChanged() signal 
as an indications that sockets have potentially broken and need to be 
reconnected.

Cheers,

-- 
Aaron McCarthy



More information about the Interest mailing list