diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2017-05-14 17:10:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-14 17:10:39 +0200 |
commit | 3afd852f54df2a0bc06be34d06509dfb2b9c80c5 (patch) | |
tree | baa4d2eba0f88403376cfaab6c4763d61934c583 /lib | |
parent | ec50dab57d91fb33380a39479bafbeae48ed1a83 (diff) | |
download | Nim-3afd852f54df2a0bc06be34d06509dfb2b9c80c5.tar.gz |
Fixes #5532 win async write (#5791)
* nimgrab tool bugfix: don't divide by zero * fixes #5532 (asyncfile write on Windows) * add a comment about what has been tried instead
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/asyncfile.nim | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/pure/asyncfile.nim b/lib/pure/asyncfile.nim index 9bd060e30..8fb30075c 100644 --- a/lib/pure/asyncfile.nim +++ b/lib/pure/asyncfile.nim @@ -339,13 +339,17 @@ proc writeBuffer*(f: AsyncFile, buf: pointer, size: int): Future[void] = if not retFuture.finished: if errcode == OSErrorCode(-1): assert bytesCount == size.int32 - f.offset.inc(size) retFuture.complete() else: retFuture.fail(newException(OSError, osErrorMsg(errcode))) ) + # passing -1 here should work according to MSDN, but doesn't. For more + # information see + # http://stackoverflow.com/questions/33650899/does-asynchronous-file- + # appending-in-windows-preserve-order ol.offset = DWord(f.offset and 0xffffffff) ol.offsetHigh = DWord(f.offset shr 32) + f.offset.inc(size) # According to MSDN we're supposed to pass nil to lpNumberOfBytesWritten. let ret = writeFile(f.fd.Handle, buf, size.int32, nil, @@ -364,7 +368,6 @@ proc writeBuffer*(f: AsyncFile, buf: pointer, size: int): Future[void] = retFuture.fail(newException(OSError, osErrorMsg(osLastError()))) else: assert bytesWritten == size.int32 - f.offset.inc(size) retFuture.complete() else: var written = 0 @@ -410,7 +413,6 @@ proc write*(f: AsyncFile, data: string): Future[void] = if not retFuture.finished: if errcode == OSErrorCode(-1): assert bytesCount == data.len.int32 - f.offset.inc(data.len) retFuture.complete() else: retFuture.fail(newException(OSError, osErrorMsg(errcode))) @@ -420,6 +422,7 @@ proc write*(f: AsyncFile, data: string): Future[void] = ) ol.offset = DWord(f.offset and 0xffffffff) ol.offsetHigh = DWord(f.offset shr 32) + f.offset.inc(data.len) # According to MSDN we're supposed to pass nil to lpNumberOfBytesWritten. let ret = writeFile(f.fd.Handle, buffer, data.len.int32, nil, @@ -441,7 +444,6 @@ proc write*(f: AsyncFile, data: string): Future[void] = retFuture.fail(newException(OSError, osErrorMsg(osLastError()))) else: assert bytesWritten == data.len.int32 - f.offset.inc(data.len) retFuture.complete() else: var written = 0 |