Source file misc/cgo/testcshared/testdata/libgo5/libgo5.go

     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  
     5  package main
     6  
     7  import "C"
     8  
     9  import (
    10  	"os"
    11  	"os/signal"
    12  	"syscall"
    13  	"time"
    14  )
    15  
    16  // The channel used to read SIGIO signals.
    17  var sigioChan chan os.Signal
    18  
    19  // CatchSIGIO starts catching SIGIO signals.
    20  //export CatchSIGIO
    21  func CatchSIGIO() {
    22  	sigioChan = make(chan os.Signal, 1)
    23  	signal.Notify(sigioChan, syscall.SIGIO)
    24  }
    25  
    26  // ResetSIGIO stops catching SIGIO signals.
    27  //export ResetSIGIO
    28  func ResetSIGIO() {
    29  	signal.Reset(syscall.SIGIO)
    30  }
    31  
    32  // SawSIGIO returns whether we saw a SIGIO within a brief pause.
    33  //export SawSIGIO
    34  func SawSIGIO() C.int {
    35  	select {
    36  	case <-sigioChan:
    37  		return 1
    38  	case <-time.After(100 * time.Millisecond):
    39  		return 0
    40  	}
    41  }
    42  
    43  func main() {
    44  }
    45  

View as plain text