github.com/iDigitalFlame/xmt@v0.5.4/examples/example_pipes.go (about)

     1  // Copyright (C) 2020 - 2023 iDigitalFlame
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU General Public License as published by
     5  // the Free Software Foundation, either version 3 of the License, or
     6  // any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU General Public License
    14  // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    15  //
    16  
    17  package main
    18  
    19  import (
    20  	"io"
    21  	"os"
    22  	"os/signal"
    23  	"syscall"
    24  
    25  	"github.com/iDigitalFlame/xmt/com/pipe"
    26  )
    27  
    28  func examplePipes() {
    29  	l, err := pipe.ListenPerms(pipe.Format("testing1"), pipe.PermEveryone)
    30  	if err != nil {
    31  		panic(err)
    32  	}
    33  
    34  	s := make(chan os.Signal, 1)
    35  	signal.Notify(s, syscall.SIGINT, syscall.SIGTERM)
    36  
    37  	go func() {
    38  		<-s
    39  		l.Close()
    40  	}()
    41  
    42  	for {
    43  		c, err := l.Accept()
    44  		if err != nil {
    45  			break
    46  		}
    47  		go io.Copy(os.Stdout, c)
    48  	}
    49  
    50  	close(s)
    51  }