From 546698a9f64a98cf483b0338ae8ab3fb346d223c Mon Sep 17 00:00:00 2001 From: Mohamed Chibani <mohamed.chibani@savoirfairelinux.com> Date: Tue, 2 Feb 2021 18:17:15 -0500 Subject: [PATCH] upnp: use asynchronous version of PUPNP DeletePortMapping method Calls to DeletePortMapping method are made synchronous which may cause lags. This might be particulary critical if the IGD does not respond fast enough since the calls are made on the shared main thread. Change-Id: I57366a70ffeb294e6277c4e8d946b339a8277309 Gitlab: #420 --- src/upnp/protocol/pupnp/pupnp.cpp | 36 ++++++++++--------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/src/upnp/protocol/pupnp/pupnp.cpp b/src/upnp/protocol/pupnp/pupnp.cpp index a9e6b35fc0..c6779a5ad1 100644 --- a/src/upnp/protocol/pupnp/pupnp.cpp +++ b/src/upnp/protocol/pupnp/pupnp.cpp @@ -1395,15 +1395,16 @@ PUPnP::actionDeletePortMapping(const UPnPIGD& igd, protocol.c_str()); action.reset(action_container_ptr); + int upnp_err = UpnpSendActionAsync(ctrlptHandle_, + igd.getControlURL().c_str(), + igd.getServiceType().c_str(), + nullptr, + action.get(), + ctrlPtCallback, + this); - int upnp_err = UpnpSendAction(ctrlptHandle_, - igd.getControlURL().c_str(), - igd.getServiceType().c_str(), - nullptr, - action.get(), - &response_container_ptr); if (upnp_err != UPNP_E_SUCCESS) { - JAMI_WARN("PUPnP: Failed to send %s from: %s, %d: %s", + JAMI_WARN("PUPnP: Failed to send %s request from: %s, %d: %s", action_name.c_str(), igd.getServiceType().c_str(), upnp_err, @@ -1411,24 +1412,9 @@ PUPnP::actionDeletePortMapping(const UPnPIGD& igd, return false; } - if (not response_container_ptr) { - JAMI_WARN("PUPnP: Failed to get response from %s", action_name.c_str()); - return false; - } - response.reset(response_container_ptr); - - // Check if there is an error code. - std::string errorCode = getFirstDocItem(response.get(), "errorCode"); - if (not errorCode.empty()) { - std::string errorDescription = getFirstDocItem(response.get(), "errorDescription"); - JAMI_WARN("PUPnP: %s returned with error: %s: %s", - action_name.c_str(), - errorCode.c_str(), - errorDescription.c_str()); - return false; - } - - JAMI_WARN("PUPnP: Closed port %s %s", port_external.c_str(), protocol.c_str()); + JAMI_DBG("PUPnP: Successfully sent %s request from %s", + action_name.c_str(), + igd.getServiceType().c_str()); return true; } -- GitLab