[swift-corelibs-dev] Swift DispatchSource not working

Pierre Habouzit phabouzit at apple.com
Fri Jul 8 11:46:53 CDT 2016


the bug is known and will be fixed in Seed 3 (?).
signal based sources are mapped to TYPE_READ by mistake in the overlay.

Matt will confirm.


-Pierre

> On Jul 7, 2016, at 7:13 PM, Darren Mo via swift-corelibs-dev <swift-corelibs-dev at swift.org> wrote:
> 
> I am trying to catch SIGWINCH (terminal window size changed) in Swift 3 (Xcode 8 beta 2). The following code should exit with a status of 1 when it receives SIGWINCH. But it never exits.
> 
> ```swift
> // compile with `xcrun -sdk macosx swiftc sigwinch.swift`
> 
> import Darwin
> import Dispatch
> 
> let source = DispatchSource.signal(signal: SIGWINCH, queue: DispatchQueue.main)
> source.setEventHandler {
>    exit(1)
> }
> source.resume()
> 
> dispatchMain()
> ```
> 
> The equivalent Objective-C code works as expected.
> 
> ```objc
> // compile with `xcrun -sdk macosx clang sigwinch.m`
> 
> #import <dispatch/dispatch.h>
> #import <signal.h>
> #import <stdlib.h>
> 
> int main() {
>    dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL,
>                                                      SIGWINCH,
>                                                      0,
>                                                      dispatch_get_main_queue());
>    dispatch_source_set_event_handler(source, ^{
>       exit(1);
>    });
>    dispatch_resume(source);
> 
>    dispatch_main();
> }
> ```
> 
> What am I doing wrong?
> _______________________________________________
> swift-corelibs-dev mailing list
> swift-corelibs-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20160708/7a2c2b50/attachment.html>


More information about the swift-corelibs-dev mailing list