parent
a29387424a
commit
e695d3bfba
1 changed files with 13 additions and 4 deletions
|
|
@ -118,8 +118,8 @@ proc readBuffer*(f: AsyncFile, buf: pointer, size: int): Future[int] =
|
||||||
## Read ``size`` bytes from the specified file asynchronously starting at
|
## Read ``size`` bytes from the specified file asynchronously starting at
|
||||||
## the current position of the file pointer.
|
## the current position of the file pointer.
|
||||||
##
|
##
|
||||||
## If the file pointer is past the end of the file then an empty string is
|
## If the file pointer is past the end of the file then zero is returned
|
||||||
## returned.
|
## and no bytes are read into ``buf``
|
||||||
var retFuture = newFuture[int]("asyncfile.readBuffer")
|
var retFuture = newFuture[int]("asyncfile.readBuffer")
|
||||||
|
|
||||||
when defined(windows) or defined(nimdoc):
|
when defined(windows) or defined(nimdoc):
|
||||||
|
|
@ -149,6 +149,10 @@ proc readBuffer*(f: AsyncFile, buf: pointer, size: int): Future[int] =
|
||||||
let err = osLastError()
|
let err = osLastError()
|
||||||
if err.int32 != ERROR_IO_PENDING:
|
if err.int32 != ERROR_IO_PENDING:
|
||||||
GC_unref(ol)
|
GC_unref(ol)
|
||||||
|
if err.int32 == ERROR_HANDLE_EOF:
|
||||||
|
# This happens in Windows Server 2003
|
||||||
|
retFuture.complete(0)
|
||||||
|
else:
|
||||||
retFuture.fail(newException(OSError, osErrorMsg(err)))
|
retFuture.fail(newException(OSError, osErrorMsg(err)))
|
||||||
else:
|
else:
|
||||||
# Request completed immediately.
|
# Request completed immediately.
|
||||||
|
|
@ -233,6 +237,11 @@ proc read*(f: AsyncFile, size: int): Future[string] =
|
||||||
dealloc buffer
|
dealloc buffer
|
||||||
buffer = nil
|
buffer = nil
|
||||||
GC_unref(ol)
|
GC_unref(ol)
|
||||||
|
|
||||||
|
if err.int32 == ERROR_HANDLE_EOF:
|
||||||
|
# This happens in Windows Server 2003
|
||||||
|
retFuture.complete("")
|
||||||
|
else:
|
||||||
retFuture.fail(newException(OSError, osErrorMsg(err)))
|
retFuture.fail(newException(OSError, osErrorMsg(err)))
|
||||||
else:
|
else:
|
||||||
# Request completed immediately.
|
# Request completed immediately.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue