mirror of https://github.com/status-im/nim-eth.git
parent
91b2b9d2ed
commit
55b9da0bea
|
@ -284,10 +284,8 @@ proc generateNewUniqueSocket[A](
|
||||||
return none[UtpSocket[A]]()
|
return none[UtpSocket[A]]()
|
||||||
|
|
||||||
proc innerConnect[A](s: UtpSocket[A]): Future[ConnectionResult[A]] {.async.} =
|
proc innerConnect[A](s: UtpSocket[A]): Future[ConnectionResult[A]] {.async.} =
|
||||||
let startFut = s.startOutgoingSocket()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await startFut
|
await s.startOutgoingSocket()
|
||||||
utp_success_outgoing.inc()
|
utp_success_outgoing.inc()
|
||||||
debug "Outgoing connection successful", dst = s.socketKey
|
debug "Outgoing connection successful", dst = s.socketKey
|
||||||
return ok(s)
|
return ok(s)
|
||||||
|
@ -304,18 +302,7 @@ proc innerConnect[A](s: UtpSocket[A]): Future[ConnectionResult[A]] {.async.} =
|
||||||
proc connect[A](s: UtpSocket[A]): Future[ConnectionResult[A]] =
|
proc connect[A](s: UtpSocket[A]): Future[ConnectionResult[A]] =
|
||||||
debug "Initiating connection", dst = s.socketKey
|
debug "Initiating connection", dst = s.socketKey
|
||||||
|
|
||||||
# Create inner future, to make sure we are installing cancelCallback
|
s.innerConnect()
|
||||||
# on whole connection future, and not only part of it
|
|
||||||
let connectionFuture = s.innerConnect()
|
|
||||||
|
|
||||||
connectionFuture.cancelCallback = proc(udata: pointer) {.gcsafe.} =
|
|
||||||
debug "Connection cancel callback fired",
|
|
||||||
socketKey = s.socketKey
|
|
||||||
# if for some reason the future is cancelled, destroy socket to clear it
|
|
||||||
# from the active socket list
|
|
||||||
s.destroy()
|
|
||||||
|
|
||||||
return connectionFuture
|
|
||||||
|
|
||||||
proc socketAlreadyExists[A](): ConnectionResult[A] =
|
proc socketAlreadyExists[A](): ConnectionResult[A] =
|
||||||
return err(OutgoingConnectionError(kind: SocketAlreadyExists))
|
return err(OutgoingConnectionError(kind: SocketAlreadyExists))
|
||||||
|
|
Loading…
Reference in New Issue