summary refs log tree commit diff stats
path: root/lib/pure/asyncfile.nim
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@gmail.com>2018-01-17 16:48:02 +0000
committerDominik Picheta <dominikpicheta@gmail.com>2018-01-28 17:13:08 +0000
commit86fb8bf723194fb1c5a21baa18b7624bfd9ca9d6 (patch)
treef09fab4b752e76b59d39d79410a16b36fbaeb3f9 /lib/pure/asyncfile.nim
parent47d05b3f2e9e9d3ca3c5050981f373a40c1533c1 (diff)
downloadNim-86fb8bf723194fb1c5a21baa18b7624bfd9ca9d6.tar.gz
Revert 3db460f5045e790b54ea382 as requested by @Araq.
Diffstat (limited to 'lib/pure/asyncfile.nim')
-rw-r--r--lib/pure/asyncfile.nim11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/pure/asyncfile.nim b/lib/pure/asyncfile.nim
index 3a9d26378..6ce9e8f75 100644
--- a/lib/pure/asyncfile.nim
+++ b/lib/pure/asyncfile.nim
@@ -81,10 +81,11 @@ proc getFileSize*(f: AsyncFile): int64 =
   else:
     result = lseek(f.fd.cint, 0, SEEK_END)
 
-proc newAsyncFile*(fd: cint | AsyncFd): AsyncFile =
+proc newAsyncFile*(fd: AsyncFd): AsyncFile =
   ## Creates `AsyncFile` with a previously opened file descriptor `fd`.
   new result
-  result.fd = register(fd)
+  result.fd = fd
+  register(fd)
 
 proc openAsync*(filename: string, mode = fmRead): AsyncFile =
   ## Opens a file specified by the path in ``filename`` using
@@ -105,7 +106,7 @@ proc openAsync*(filename: string, mode = fmRead): AsyncFile =
     if fd == INVALID_HANDLE_VALUE:
       raiseOSError(osLastError())
 
-    result = newAsyncFile(fd.cint)
+    result = newAsyncFile(fd.AsyncFd)
 
     if mode == fmAppend:
       result.offset = getFileSize(result)
@@ -115,10 +116,10 @@ proc openAsync*(filename: string, mode = fmRead): AsyncFile =
     # RW (Owner), RW (Group), R (Other)
     let perm = S_IRUSR or S_IWUSR or S_IRGRP or S_IWGRP or S_IROTH
     let fd = open(filename, flags, perm)
-    if fd.cint == -1:
+    if fd == -1:
       raiseOSError(osLastError())
 
-    result = newAsyncFile(fd)
+    result = newAsyncFile(fd.AsyncFd)
 
 proc readBuffer*(f: AsyncFile, buf: pointer, size: int): Future[int] =
   ## Read ``size`` bytes from the specified file asynchronously starting at