mirror of https://github.com/vacp2p/nim-libp2p.git
handle secure errors in readOnce (secure) (#397)
* handle secure errors in readOnce(secure) * small synthax fix * fix mistake in readOnce's isNil
This commit is contained in:
parent
bd70515087
commit
32623b930e
|
@ -120,10 +120,23 @@ method readOnce*(s: SecureConn,
|
||||||
doAssert(nbytes > 0, "nbytes must be positive integer")
|
doAssert(nbytes > 0, "nbytes must be positive integer")
|
||||||
|
|
||||||
if s.buf.data().len() == 0:
|
if s.buf.data().len() == 0:
|
||||||
let buf = await s.readMessage()
|
let (buf, err) = try:
|
||||||
|
(await s.readMessage(), nil)
|
||||||
|
except CatchableError as exc:
|
||||||
|
(@[], exc)
|
||||||
|
|
||||||
|
if not isNil(err):
|
||||||
|
warn "error while reading message from secure connection, closing.", error=err.name,
|
||||||
|
message=err.msg,
|
||||||
|
connection=s
|
||||||
|
await s.close()
|
||||||
|
raise err
|
||||||
|
|
||||||
s.activity = true
|
s.activity = true
|
||||||
|
|
||||||
if buf.len == 0:
|
if buf.len == 0:
|
||||||
raise newLPStreamIncompleteError()
|
raise newLPStreamIncompleteError()
|
||||||
|
|
||||||
s.buf.add(buf)
|
s.buf.add(buf)
|
||||||
|
|
||||||
var p = cast[ptr UncheckedArray[byte]](pbytes)
|
var p = cast[ptr UncheckedArray[byte]](pbytes)
|
||||||
|
|
Loading…
Reference in New Issue