Skip to content

Commit

Permalink
Windows: make sure wsaStartup() is called before we use sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
stefantalpalaru committed Apr 24, 2019
1 parent 037a81b commit ea89abd
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions nat_traversal/miniupnpc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ else:
{.passL: includePath / "libminiupnpc.a".}

when defined(windows):
import nativesockets # for that wsaStartup() call at the end
{.passC: "-DMINIUPNP_STATICLIB".}
{.passL: "-lws2_32 -liphlpapi".}

Expand Down Expand Up @@ -533,10 +534,9 @@ proc miniupnpFinalizer(x: Miniupnp) =

proc newMiniupnp*(): Miniupnp =
new(result, miniupnpFinalizer)
if result.ttl == 0.cuchar:
result.ttl = 2.cuchar
result.ttl = 2.cuchar

proc `=deepCopy`(x: Miniupnp): Miniupnp =
proc `=deepCopy`*(x: Miniupnp): Miniupnp =
doAssert(false, "not implemented")

proc upnpError*(errno: cint): cstring =
Expand All @@ -556,9 +556,12 @@ proc discover*(self: Miniupnp): Result[int, cstring] =
if self.devList != nil:
freeUPNPDevlist(self.devList)
self.error = 0
var
multicastIF = if self.multicastIF.len > 0: self.multicastIF.cstring else: nil
miniSsdpdSocket = if self.miniSsdpdSocket.len > 0: self.miniSsdpdSocket.cstring else: nil
self.devList = upnpDiscover(self.discoverDelay,
self.multicastIF.cstring,
self.minisSdpdSocket.cstring,
multicastIF,
miniSsdpdSocket,
self.localPort,
self.ipv6,
self.ttl,
Expand Down

0 comments on commit ea89abd

Please sign in to comment.