support compilation with Nim-1.4 HEAD (#521)

This commit is contained in:
Ștefan Talpalaru 2021-02-08 22:21:43 +01:00 committed by GitHub
parent 2658181df9
commit d9563d65ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -103,8 +103,16 @@ proc dialAndUpgrade(s: Switch,
addrs: seq[MultiAddress]): addrs: seq[MultiAddress]):
Future[Connection] {.async.} = Future[Connection] {.async.} =
debug "Dialing peer", peerId debug "Dialing peer", peerId
# Avoid "cannot be captured as it would violate memory safety" errors in Nim-1.4.x.
var
transport: Transport
address: MultiAddress
for t in s.transports: # for each transport for t in s.transports: # for each transport
transport = t
for a in addrs: # for each address for a in addrs: # for each address
address = a
if t.handles(a): # check if it can dial it if t.handles(a): # check if it can dial it
trace "Dialing address", address = $a, peerId trace "Dialing address", address = $a, peerId
let dialed = try: let dialed = try:
@ -112,7 +120,7 @@ proc dialAndUpgrade(s: Switch,
# await a connection slot when the total # await a connection slot when the total
# connection count is equal to `maxConns` # connection count is equal to `maxConns`
await s.connManager.trackOutgoingConn( await s.connManager.trackOutgoingConn(
() => t.dial(a) () => transport.dial(address)
) )
except TooManyConnectionsError as exc: except TooManyConnectionsError as exc:
trace "Connection limit reached!" trace "Connection limit reached!"