当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.Mkfifo函数代码示例

本文整理汇总了Golang中syscall.Mkfifo函数的典型用法代码示例。如果您正苦于以下问题:Golang Mkfifo函数的具体用法?Golang Mkfifo怎么用?Golang Mkfifo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Mkfifo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Run

func (fifo *FIFOReader) Run(dest chan<- Message) {
	var err error

	syscall.Mkfifo(fifo.Source, 0644)
	fifo.fi_des, err = os.OpenFile(fifo.Source, os.O_RDONLY, 0644)
	if err != nil {
		fifo.errchan <- &InputError{fifo.Driver, fifo.Id, "FIFO " + fifo.Source, err}
		return
	}

	data := make(chan string, 100)
	defer fifo.fi_des.Close()

	go reader_to_channel(fifo.fi_des, data)

	for {
		select {
		case line := <-data:
			dest <- packmsg(fifo.Id, syslog5424.CreateMessage(fifo.AppName, *fifo.prio, line))

		case <-fifo.end:
			return
		}
	}
}
开发者ID:nathanaelle,项目名称:mercury,代码行数:25,代码来源:fifo.go

示例2: PreparePipe

func PreparePipe() string {

	path := "/tmp/" + RandStringBytes(10)

	pipeExists := false
	fileInfo, err := os.Stat(path)

	if err == nil {
		if (fileInfo.Mode() & os.ModeNamedPipe) > 0 {
			pipeExists = true
		} else {
			log.Printf("%d != %d\n", os.ModeNamedPipe, fileInfo.Mode())
			panic(path + " exists, but it's not a named pipe (FIFO)")
		}
	}

	// Try to create pipe if needed
	if !pipeExists {
		err := syscall.Mkfifo(path, 0666)
		if err != nil {
			panic(err.Error())
		}
	}
	return path
}
开发者ID:fasmide,项目名称:glowing-old-crt,代码行数:25,代码来源:OmxPlayer.go

示例3: receiveSignalsFIFO

// Create a signaling named pipe and feed offers from it into
// makePeerConnectionFromOffer.
func receiveSignalsFIFO(filename string, config *webrtc.Configuration) error {
	err := syscall.Mkfifo(filename, 0600)
	if err != nil {
		if err.(syscall.Errno) != syscall.EEXIST {
			return err
		}
	}
	signalFile, err := os.OpenFile(filename, os.O_RDONLY, 0600)
	if err != nil {
		return err
	}
	defer signalFile.Close()

	s := bufio.NewScanner(signalFile)
	for s.Scan() {
		msg := s.Text()
		sdp := webrtc.DeserializeSessionDescription(msg)
		if sdp == nil {
			log.Printf("ignoring invalid signal message %+q", msg)
			continue
		}

		pc, err := makePeerConnectionFromOffer(sdp, config)
		if err != nil {
			log.Printf("makePeerConnectionFromOffer: %s", err)
			continue
		}
		// Write offer to log for manual signaling.
		log.Printf("----------------")
		fmt.Fprintln(logFile, pc.LocalDescription().Serialize())
		log.Printf("----------------")
	}
	return s.Err()
}
开发者ID:pculka,项目名称:snowflake,代码行数:36,代码来源:snowflake.go

示例4: NewContainerProcess

func NewContainerProcess(cs *ContainerdSuite, bundle *Bundle, cid, pid string) (c *containerProcess, err error) {
	c = &containerProcess{
		containerId: cid,
		pid:         "init",
		bundle:      bundle,
		eventsCh:    make(chan *types.Event, 8),
		cs:          cs,
		hasExited:   false,
	}

	for name, path := range map[string]*string{
		"stdin":  &c.io.stdin,
		"stdout": &c.io.stdout,
		"stderr": &c.io.stderr,
	} {
		*path = filepath.Join(bundle.Path, "io", cid+"-"+pid+"-"+name)
		if err = syscall.Mkfifo(*path, 0755); err != nil && !os.IsExist(err) {
			return nil, err
		}
	}

	if err = c.openIo(); err != nil {
		return nil, err
	}

	return c, nil
}
开发者ID:carriercomm,项目名称:containerd,代码行数:27,代码来源:container_utils_test.go

示例5: Open

func Open() (*Fifo, error) {
	var pipe Fifo
	pipe.path = defaultPath
	if config.Has("global.fifo") {
		pipe.path, _ = config.String("config.fifo")
	}

	if _, err := os.Stat(pipe.path); err == nil {
		err = os.Remove(pipe.path)
		if err != nil {
			return nil, err
		}
	}

	if err := syscall.Mkfifo(pipe.path, 0777); err != nil {
		return nil, err
	}

	fd, err := syscall.Open(pipe.path, syscall.O_RDONLY|syscall.O_NONBLOCK, 0777)
	if err != nil {
		return nil, err
	}

	pipe.fd = fdReader(fd)
	pipe.rd = bufio.NewReader(pipe.fd)
	pipe.cmds = make([]Command, 0, 5)
	return &pipe, nil
}
开发者ID:lucas8,项目名称:notifier,代码行数:28,代码来源:fifo.go

示例6: openGStreamer

// openGStreamer runs a gstreamer subcommand and pipes it's output.
func openGStreamer() (io.Reader, error) {
	fifo := "fifo" + path.Base(*flagSrc)
	if err := syscall.Mkfifo(fifo, 0666); err != nil {
		fmt.Fprintln(os.Stderr, "mkfifo", fifo, ":", err)
	}

	bin := "gst-launch-1.0"
	args := fmt.Sprintf(`v4l2src device=%s ! video/x-raw,framerate=%d/1,width=%d,height=%d ! jpegenc quality=%d ! filesink buffer-size=0 location=%v`, *flagSrc, *flagFPS, *flagWidth, *flagHeight, *flagQuality, fifo)

	fmt.Println(bin, args)
	cmd := exec.Command(bin, strings.Split(args, " ")...)

	stderr, err := cmd.StderrPipe()
	if err != nil {
		return nil, err
	}
	go io.Copy(os.Stderr, stderr)

	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return nil, err
	}
	go io.Copy(os.Stderr, stdout)

	if err := cmd.Start(); err != nil {
		return nil, err
	}

	f, err := os.Open(fifo)
	if err != nil {
		return nil, err
	}
	return f, nil
}
开发者ID:barnex,项目名称:ev3cam,代码行数:35,代码来源:gstreamer.go

示例7: mkfifo

func mkfifo(t *testing.T) {
	_ = syscall.Unlink(fifo)
	err := syscall.Mkfifo(fifo, 0666)
	if err != nil {
		t.Fatal("mkfifo:", err)
	}
}
开发者ID:npat-efault,项目名称:pollfd,代码行数:7,代码来源:pollfd_test.go

示例8: createFDProxies

// createFDProxies creates pipes at /dev/stdout and /dev/stderr and copies data
// written to them to the job's stdout and stderr streams respectively.
//
// This is necessary (rather than just symlinking those paths to /proc/self/fd/{1,2})
// because the standard streams are sockets, and calling open(2) on a socket
// leads to an ENXIO error (see http://marc.info/?l=ast-users&m=120978595414993).
func createFDProxies(cmd *exec.Cmd) error {
	for path, dst := range map[string]*os.File{
		"/dev/stdout": cmd.Stdout.(*os.File),
		"/dev/stderr": cmd.Stderr.(*os.File),
	} {
		os.Remove(path)
		if err := syscall.Mkfifo(path, 0666); err != nil {
			return err
		}
		pipe, err := os.OpenFile(path, os.O_RDWR, os.ModeNamedPipe)
		if err != nil {
			return err
		}
		go func(dst *os.File) {
			defer pipe.Close()
			for {
				// copy data from the pipe to dst using splice(2) (rather than io.Copy)
				// to avoid a needless copy through user space
				n, err := syscall.Splice(int(pipe.Fd()), nil, int(dst.Fd()), nil, 65535, 0)
				if err != nil || n == 0 {
					return
				}
			}
		}(dst)
	}
	return nil
}
开发者ID:ably-forks,项目名称:flynn,代码行数:33,代码来源:init.go

示例9: Run

func (fifo *FIFOReader) Run(dest chan<- Message, errchan chan<- error) {
	var err error
	fifo.end = make(chan bool, 1)
	fifo.prio, err = message.PriorityDecode(fifo.Priority)
	if err != nil {
		errchan <- &InputError{fifo.Driver, fifo.Id, "Priority " + fifo.Priority, err}
		return
	}

	syscall.Mkfifo(fifo.Source, 0644)
	fifo.fi_des, err = os.OpenFile(fifo.Source, os.O_RDONLY, 0644)
	if err != nil {
		errchan <- &InputError{fifo.Driver, fifo.Id, "FIFO " + fifo.Source, err}
		return
	}

	data := make(chan string)
	defer fifo.fi_des.Close()

	go reader_to_channel(fifo.fi_des, data)

	for {
		select {
		case line := <-data:
			dest <- packmsg(fifo.Id, *message.CreateMessage(line, fifo.AppName, fifo.prio))

		case <-fifo.end:
			return
		}
	}
}
开发者ID:keltia,项目名称:mercury,代码行数:31,代码来源:fifo.go

示例10: mkFifo

func mkFifo(t *testing.T, i int) {
	name := fifoName(i)
	syscall.Unlink(name)
	err := syscall.Mkfifo(name, 0666)
	if err != nil {
		t.Fatalf("mkfifo %s: %v", name, err)
	}
}
开发者ID:dullgiulio,项目名称:poller,代码行数:8,代码来源:poller_test.go

示例11: getExitPipe

func getExitPipe(path string) (*os.File, error) {
	if err := syscall.Mkfifo(path, 0755); err != nil && !os.IsExist(err) {
		return nil, err
	}
	// add NONBLOCK in case the other side has already closed or else
	// this function would never return
	return os.OpenFile(path, syscall.O_RDONLY|syscall.O_NONBLOCK, 0)
}
开发者ID:Altiscale,项目名称:containerd,代码行数:8,代码来源:process.go

示例12: make

func (inode *SpecialInode) make(name string) error {
	if inode.Mode&syscall.S_IFBLK != 0 || inode.Mode&syscall.S_IFCHR != 0 {
		return syscall.Mknod(name, uint32(inode.Mode), int(inode.Rdev))
	} else if inode.Mode&syscall.S_IFIFO != 0 {
		return syscall.Mkfifo(name, uint32(inode.Mode))
	} else {
		return errors.New("unsupported mode")
	}
}
开发者ID:JohnTheodore,项目名称:Dominator,代码行数:9,代码来源:write.go

示例13: mkfifos

func (p *process) mkfifos() error {
	for _, pipe := range []string{p.stdin, p.stdout, p.stderr, p.winsz, p.exit} {
		if err := syscall.Mkfifo(pipe, 0); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:cloudfoundry,项目名称:guardian,代码行数:9,代码来源:execrunner.go

示例14: TempFifo

func TempFifo(t *testing.T) *Fifo {

	name := os.TempDir() + "/fifo2kinesis-" + RandomString(8) + ".pipe"
	err := syscall.Mkfifo(name, 0600)
	if err != nil {
		t.Errorf("error creating fifo: %s", err)
	}

	return &Fifo{name}
}
开发者ID:acquia,项目名称:fifo2kinesis,代码行数:10,代码来源:fifo_test.go

示例15: TestBuildFailsForUnknownType

func (s *BuildTestSuite) TestBuildFailsForUnknownType(c *C) {
	sourceDir := makeExampleSnapSourceDir(c, `name: hello
version: 1.0.1
`)
	err := syscall.Mkfifo(filepath.Join(sourceDir, "fifo"), 0644)
	c.Assert(err, IsNil)

	_, err = BuildSquashfsSnap(sourceDir, "")
	c.Assert(err, ErrorMatches, "can not handle type of file .*")
}
开发者ID:dholbach,项目名称:snappy,代码行数:10,代码来源:build_test.go


注:本文中的syscall.Mkfifo函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。