Raise disconnect exception in fullRecvInto

This commit is contained in:
Yuriy Glukhov 2018-05-16 11:25:23 +03:00
parent 98cf6376c8
commit 6ec49cea9c
1 changed files with 5 additions and 2 deletions

View File

@ -223,8 +223,11 @@ proc fullRecvInto(s: AsyncSocket, buffer: pointer, bufferLen: int) {.async.} =
# XXX: This should be a library function # XXX: This should be a library function
var receivedBytes = 0 var receivedBytes = 0
while receivedBytes < bufferLen: while receivedBytes < bufferLen:
receivedBytes += await s.recvInto(buffer.shift(receivedBytes), let sz = await s.recvInto(buffer.shift(receivedBytes),
bufferLen - receivedBytes) bufferLen - receivedBytes)
if sz == 0:
raise newException(IOError, "Socket disconnected")
receivedBytes += sz
template fullRecvInto(s: AsyncSocket, buff: var openarray[byte]): auto = template fullRecvInto(s: AsyncSocket, buff: var openarray[byte]): auto =
fullRecvInto(s, addr buff[0], buff.len) fullRecvInto(s, addr buff[0], buff.len)