Skip to content

Commit 7ee8dc8

Browse files
committed
Do call the rety of CreatePortMapAsync inside CreatePortMapAsync with await.
1 parent c671a0f commit 7ee8dc8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Open.Nat/Upnp/UpnpNatDevice.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public override async Task CreatePortMapAsync(Mapping mapping)
145145
if(mapping.PrivateIP.Equals(IPAddress.None)) mapping.PrivateIP = DeviceInfo.LocalAddress;
146146

147147
NatDiscoverer.TraceSource.LogInfo("CreatePortMapAsync - Creating port mapping {0}", mapping);
148+
bool retry = false;
148149
try
149150
{
150151
var message = new CreatePortMappingRequestMessage(mapping);
@@ -162,17 +163,17 @@ await _soapClient
162163
mapping.Lifetime = 0;
163164
// We create the mapping anyway. It must be released on shutdown.
164165
mapping.LifetimeType = MappingLifetime.ForcedSession;
165-
CreatePortMapAsync(mapping);
166+
retry = true;
166167
break;
167168
case UpnpConstants.SamePortValuesRequired:
168169
NatDiscoverer.TraceSource.LogWarn("Same Port Values Required - Using internal port {0}", mapping.PrivatePort);
169170
mapping.PublicPort = mapping.PrivatePort;
170-
CreatePortMapAsync(mapping);
171+
retry = true;
171172
break;
172173
case UpnpConstants.RemoteHostOnlySupportsWildcard:
173174
NatDiscoverer.TraceSource.LogWarn("Remote Host Only Supports Wildcard");
174175
mapping.PublicIP = IPAddress.None;
175-
CreatePortMapAsync(mapping);
176+
retry = true;
176177
break;
177178
case UpnpConstants.ExternalPortOnlySupportsWildcard:
178179
NatDiscoverer.TraceSource.LogWarn("External Port Only Supports Wildcard");
@@ -185,6 +186,8 @@ await _soapClient
185186
throw;
186187
}
187188
}
189+
if (retry)
190+
await CreatePortMapAsync(mapping);
188191
}
189192
#endif
190193

0 commit comments

Comments
 (0)