fix 'seq changed while iterating' bug
This commit is contained in:
parent
6e7ab9369d
commit
272cb2f497
18
quicp2p.nim
18
quicp2p.nim
|
@ -172,25 +172,27 @@ proc initContext(sock: AsyncSocket, certChainPath: string, keyPath: string,
|
|||
result.tlsCtx.signCertificate = addr result.signCertificate.super
|
||||
|
||||
proc sendPackets(ctx: QuicP2PContext) =
|
||||
for c in ctx.connections:
|
||||
let conns = ctx.connections
|
||||
for i in 0 .. conns.len - 1:
|
||||
var srcAddr, dstAddr: quicly_address_t
|
||||
var dgrams: array[10, IOVec]
|
||||
var dgramCount = dgrams.len().csize_t
|
||||
var dgramsBuf = newString(dgramCount * ctx.quiclyCtx.transport_params.max_udp_payload_size)
|
||||
let sendResult = quicly_send(c, addr dstAddr, addr srcAddr, addr dgrams[0],
|
||||
addr dgramCount, addr dgramsBuf[0],
|
||||
dgramsBuf.len().csize_t)
|
||||
let sendResult = quicly_send(conns[i], addr dstAddr, addr srcAddr,
|
||||
addr dgrams[0], addr dgramCount,
|
||||
addr dgramsBuf[0], dgramsBuf.len().csize_t)
|
||||
case sendResult:
|
||||
of 0:
|
||||
if dgramCount > 0:
|
||||
echo &"sending {dgramCount} datagrams"
|
||||
for i in 0 .. dgramCount - 1:
|
||||
for j in 0 .. dgramCount - 1:
|
||||
var sockLen = quicly_get_socklen(addr dstAddr.sa)
|
||||
# TODO: replace asyncdispatch.sendTo with asyncnet.sendTo (Nim 1.4 required)
|
||||
asyncCheck sendTo(ctx.sock.getFd().AsyncFD, dgrams[i].iov_base,
|
||||
dgrams[i].iov_len.int, addr dstAddr.sa, sockLen)
|
||||
asyncCheck sendTo(ctx.sock.getFd().AsyncFD, dgrams[j].iov_base,
|
||||
dgrams[j].iov_len.int, addr dstAddr.sa, sockLen)
|
||||
of QUICLY_ERROR_FREE_CONNECTION:
|
||||
ctx.connections.del(ctx.connections.find(c))
|
||||
let c = ctx.connections[i]
|
||||
ctx.connections.del(i)
|
||||
quicly_free(c)
|
||||
else:
|
||||
raise newException(ValueError, &"quicly_send returned {sendResult}")
|
||||
|
|
Loading…
Reference in New Issue