diff options
author | Dominik Picheta <dominikpicheta@gmail.com> | 2018-01-17 16:48:02 +0000 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@gmail.com> | 2018-01-28 17:13:08 +0000 |
commit | 86fb8bf723194fb1c5a21baa18b7624bfd9ca9d6 (patch) | |
tree | f09fab4b752e76b59d39d79410a16b36fbaeb3f9 /lib | |
parent | 47d05b3f2e9e9d3ca3c5050981f373a40c1533c1 (diff) | |
download | Nim-86fb8bf723194fb1c5a21baa18b7624bfd9ca9d6.tar.gz |
Revert 3db460f5045e790b54ea382 as requested by @Araq.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/asyncdispatch.nim | 28 | ||||
-rw-r--r-- | lib/pure/asyncfile.nim | 11 | ||||
-rw-r--r-- | lib/pure/asyncnet.nim | 2 |
3 files changed, 14 insertions, 27 deletions
diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index 0539706a9..598b0195b 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -222,7 +222,7 @@ when defined(windows) or defined(nimdoc): PCustomOverlapped* = ref CustomOverlapped - AsyncFD* = distinct int ## An FD that is registered in the dispatcher. + AsyncFD* = distinct int PostCallbackData = object ioPort: Handle @@ -270,22 +270,14 @@ when defined(windows) or defined(nimdoc): ## (Unix) for the specified dispatcher. return disp.ioPort - proc register*(fd: cint | SocketHandle | AsyncFD): AsyncFD {.discardable.} = + proc register*(fd: AsyncFD) = ## Registers ``fd`` with the dispatcher. - ## - ## By convention, an ``AsyncFD`` is said to be already registered in the - ## dispatcher. This procedure will raise an exception if ``fd`` has already - ## been registered, but only if the type of the ``fd`` isn't ``AsyncFD``. let p = getGlobalDispatcher() - when fd is AsyncFD: - if fd in p.handles: - return if createIoCompletionPort(fd.Handle, p.ioPort, cast[CompletionKey](fd), 1) == 0: raiseOSError(osLastError()) - p.handles.incl(fd.AsyncFD) - return fd.AsyncFD + p.handles.incl(fd) proc verifyPresence(fd: AsyncFD) = ## Ensures that file descriptor has been registered with the dispatcher. @@ -771,8 +763,8 @@ when defined(windows) or defined(nimdoc): ## Unregisters ``fd``. getGlobalDispatcher().handles.excl(fd) - proc contains*(disp: PDispatcher, fd: AsyncFd | SocketHandle): bool = - return fd.SocketHandle in disp.handles + proc contains*(disp: PDispatcher, fd: AsyncFD): bool = + return fd in disp.handles {.push stackTrace:off.} proc waitableCallback(param: pointer, @@ -994,7 +986,7 @@ when defined(windows) or defined(nimdoc): proc newAsyncEvent*(): AsyncEvent = ## Creates a new thread-safe ``AsyncEvent`` object. ## - ## New ``AsyncEvent`` object is not automatically registered with # TODO: Why? -- DP + ## New ``AsyncEvent`` object is not automatically registered with ## dispatcher like ``AsyncSocket``. var sa = SECURITY_ATTRIBUTES( nLength: sizeof(SECURITY_ATTRIBUTES).cint, @@ -1115,14 +1107,10 @@ else: proc getIoHandler*(disp: PDispatcher): Selector[AsyncData] = return disp.selector - proc register*(fd: cint | SocketHandle | AsyncFD): AsyncFD {.discardable.} = + proc register*(fd: AsyncFD) = let p = getGlobalDispatcher() - when fd is AsyncFD: - if fd.SocketHandle in p.selector: - return var data = newAsyncData() p.selector.registerHandle(fd.SocketHandle, {}, data) - return fd.AsyncFD proc closeSocket*(sock: AsyncFD) = let disp = getGlobalDispatcher() @@ -1135,7 +1123,7 @@ else: proc unregister*(ev: AsyncEvent) = getGlobalDispatcher().selector.unregister(SelectEvent(ev)) - proc contains*(disp: PDispatcher, fd: AsyncFd | SocketHandle): bool = + proc contains*(disp: PDispatcher, fd: AsyncFd): bool = return fd.SocketHandle in disp.selector proc addRead*(fd: AsyncFD, cb: Callback) = 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 diff --git a/lib/pure/asyncnet.nim b/lib/pure/asyncnet.nim index adee34b9e..bdbf47004 100644 --- a/lib/pure/asyncnet.nim +++ b/lib/pure/asyncnet.nim @@ -146,8 +146,6 @@ proc newAsyncSocket*(fd: AsyncFD, domain: Domain = AF_INET, ## **Note**: This procedure will **NOT** register ``fd`` with the global ## async dispatcher. You need to do this manually. If you have used ## ``newAsyncNativeSocket`` to create ``fd`` then it's already registered. - ## The reason for this is that the ``AsyncFD`` type is a special type for an - ## FD that signifies that its been registered. assert fd != osInvalidSocket.AsyncFD new(result) result.fd = fd.SocketHandle |