Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Aug 5, 2024
1 parent 4c5ea87 commit 83c53f1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libp2p/transports/tcptransport.nim
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,20 @@ method accept*(self: TcpTransport): Future[Connection] =
raise newTransportClosedError()

if self.acceptFuts.len <= 0:
# Holds futures representing ongoing accept calls on multiple servers.
self.acceptFuts = self.servers.mapIt(it.accept())

let
finished =
try:
# Waits for any one of these futures to complete, indicating that a new connection has been accepted on one of the servers.
await one(self.acceptFuts)
except ValueError:
raise (ref TcpTransportError)(msg: "No listeners configured")
index = self.acceptFuts.find(finished)

# A new connection has been accepted. The corresponding server should immediately start accepting another connection.
# Thus we replace the completed future with a new one by calling accept on the same server again.
self.acceptFuts[index] = self.servers[index].accept()
let transp =
try:
Expand Down

0 comments on commit 83c53f1

Please sign in to comment.