Skip to content

Commit d2d3e05

Browse files
committed
GenericConnectionHandler: allow switching network interface if inactive
1 parent fa8e957 commit d2d3e05

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/GenericConnectionHandler.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,32 @@
1818
static inline ConnectionHandler* instantiate_handler(NetworkAdapter adapter);
1919

2020
bool GenericConnectionHandler::updateSetting(const models::NetworkSetting& s) {
21-
if(_ch != nullptr && _ch->_current_net_connection_state != NetworkConnectionState::INIT) {
22-
// If the internal connection handler is already being used and not in INIT phase we cannot update the settings
23-
return false;
24-
} else if(_ch != nullptr && _ch->_current_net_connection_state == NetworkConnectionState::INIT && _interface != s.type) {
25-
// If the internal connection handler is already being used and in INIT phase and the interface type is being changed
26-
// -> we need to deallocate the previously allocated handler
27-
21+
if (_ch != nullptr) {
22+
if (_ch->_current_net_connection_state == NetworkConnectionState::CONNECTING ||
23+
_ch->_current_net_connection_state == NetworkConnectionState::CONNECTED ||
24+
_ch->_current_net_connection_state == NetworkConnectionState::DISCONNECTING) {
25+
// If the internal connection handler is already being used and active we cannot update the settings
26+
return false;
27+
} else if(_interface != s.type) {
28+
// If the internal connection handler is not active and the interface type is being changed
29+
// -> we need to deallocate the previously allocated handler
30+
delete _ch;
31+
_ch = nullptr;
32+
}
2833
// if interface type is not being changed -> we just need to call updateSettings
29-
delete _ch;
30-
_ch = nullptr;
3134
}
3235

33-
if(_ch == nullptr) {
36+
if (_ch == nullptr) {
3437
_ch = instantiate_handler(s.type);
3538
}
3639

37-
if(_ch != nullptr) {
40+
if (_ch != nullptr) {
3841
_interface = s.type;
3942
_ch->setKeepAlive(_keep_alive);
4043
_ch->enableCheckInternetAvailability(_check_internet_availability);
4144
return _ch->updateSetting(s);
4245
} else {
4346
_interface = NetworkAdapter::NONE;
44-
4547
return false;
4648
}
4749
}

0 commit comments

Comments
 (0)