github.com/likebike/go--@v0.0.0-20190911215757-0bd925d16e96/go/misc/cgo/testcarchive/src/libgo3/libgo3.go (about)

     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  // ProvokeSIGPIPE provokes a kernel-initiated SIGPIPE.
    44  //export ProvokeSIGPIPE
    45  func ProvokeSIGPIPE() {
    46  	r, w, err := os.Pipe()
    47  	if err != nil {
    48  		panic(err)
    49  	}
    50  	r.Close()
    51  	defer w.Close()
    52  	w.Write([]byte("some data"))
    53  }
    54  
    55  func main() {
    56  }