Attempt to fix datagram bug.

This commit is contained in:
cheatfate 2018-06-05 11:31:18 +03:00
parent 3cb521c920
commit 6f8be9f067
1 changed files with 9 additions and 7 deletions

View File

@ -141,6 +141,7 @@ proc test1(): Future[int] {.async.} =
await dgram2.sendTo(addr data[0], len(data), ta) await dgram2.sendTo(addr data[0], len(data), ta)
await dgram2.join() await dgram2.join()
dgram1.close() dgram1.close()
dgram2.close()
result = counter result = counter
proc test2(): Future[int] {.async.} = proc test2(): Future[int] {.async.} =
@ -152,6 +153,7 @@ proc test2(): Future[int] {.async.} =
await dgram2.send(addr data[0], len(data)) await dgram2.send(addr data[0], len(data))
await dgram2.join() await dgram2.join()
dgram1.close() dgram1.close()
dgram2.close()
result = counter result = counter
proc waitAll(futs: seq[Future[void]]): Future[void] = proc waitAll(futs: seq[Future[void]]): Future[void] =
@ -170,18 +172,18 @@ proc test3(bounded: bool): Future[int] {.async.} =
var counter = 0 var counter = 0
var dgram1 = newDatagramTransport(client1, udata = addr counter, local = ta) var dgram1 = newDatagramTransport(client1, udata = addr counter, local = ta)
var clients = newSeq[Future[void]](ClientsCount) var clients = newSeq[Future[void]](ClientsCount)
var grams = newSeq[DatagramTransport](ClientsCount)
var counters = newSeq[int](ClientsCount) var counters = newSeq[int](ClientsCount)
var dgram: DatagramTransport
for i in 0..<ClientsCount: for i in 0..<ClientsCount:
var data = "REQUEST0" var data = "REQUEST0"
if bounded: if bounded:
dgram = newDatagramTransport(client4, udata = addr counters[i], grams[i] = newDatagramTransport(client4, udata = addr counters[i],
remote = ta) remote = ta)
await dgram.send(addr data[0], len(data)) await grams[i].send(addr data[0], len(data))
else: else:
dgram = newDatagramTransport(client5, udata = addr counters[i]) grams[i] = newDatagramTransport(client5, udata = addr counters[i])
await dgram.sendTo(addr data[0], len(data), ta) await grams[i].sendTo(addr data[0], len(data), ta)
clients[i] = dgram.join() clients[i] = grams[i].join()
await waitAll(clients) await waitAll(clients)
dgram1.close() dgram1.close()