1// Copyright 2015 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package main
6
7import "C"
8
9import (
10	"os"
11	"os/signal"
12	"syscall"
13	"time"
14)
15
16// The channel used to read SIGIO signals.
17var sigioChan chan os.Signal
18
19// CatchSIGIO starts catching SIGIO signals.
20//
21//export CatchSIGIO
22func CatchSIGIO() {
23	sigioChan = make(chan os.Signal, 1)
24	signal.Notify(sigioChan, syscall.SIGIO)
25}
26
27// ResetSIGIO stops catching SIGIO signals.
28//
29//export ResetSIGIO
30func ResetSIGIO() {
31	signal.Reset(syscall.SIGIO)
32}
33
34// AwaitSIGIO blocks indefinitely until a SIGIO is reported.
35//
36//export AwaitSIGIO
37func AwaitSIGIO() {
38	<-sigioChan
39}
40
41// SawSIGIO reports whether we saw a SIGIO within a brief pause.
42//
43//export SawSIGIO
44func SawSIGIO() bool {
45	timer := time.NewTimer(100 * time.Millisecond)
46	select {
47	case <-sigioChan:
48		timer.Stop()
49		return true
50	case <-timer.C:
51		return false
52	}
53}
54
55func main() {
56}
57