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


Golang syscall.Socketpair函数代码示例

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


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

示例1: createAttachment

func createAttachment(stream *spdystream.Stream) (*os.File, error) {
	if stream.IsFinished() {
		return nil, fmt.Errorf("stream already finished")
	}

	socketFds, socketErr := syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_STREAM|syscall.FD_CLOEXEC, 0)
	if socketErr != nil {
		return nil, socketErr
	}
	pipe := os.NewFile(uintptr(socketFds[1]), "")
	defer pipe.Close()
	conn, connErr := net.FileConn(pipe)
	if connErr != nil {
		return nil, connErr
	}

	go func() {
		io.Copy(conn, stream)
		conn.Close()
	}()
	go func() {
		io.Copy(stream, conn)
	}()

	return os.NewFile(uintptr(socketFds[0]), ""), nil
}
开发者ID:ndeloof,项目名称:libchan,代码行数:26,代码来源:spdy.go

示例2: newFakeVTYServer

func newFakeVTYServer() (*fakeVTYServer, error) {
	fds, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
	if err != nil {
		return nil, err
	}

	vtyClientFile := os.NewFile(uintptr(fds[1]), "vty-client")
	vtyClientConn, err := net.FileConn(vtyClientFile)
	if err != nil {
		return nil, err
	}

	vtyServerFile := os.NewFile(uintptr(fds[0]), "vty-server")
	vtyServerConn, err := net.FileConn(vtyServerFile)
	if err != nil {
		return nil, err
	}
	syscall.SetNonblock(fds[0], false)

	vs := &fakeVTYServer{
		clientConn: vtyClientConn,
		serverConn: vtyServerConn,
		clientFile: vtyClientFile,
		serverFile: vtyServerFile,

		send:     make(chan []byte),
		received: make(chan []byte),
	}

	go vs.read()
	go vs.write()

	return vs, nil
}
开发者ID:Cepave,项目名称:lvs-metrics,代码行数:34,代码来源:vty_test.go

示例3: newPipe

func newPipe() (parent *os.File, child *os.File, err error) {
	fds, err := syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_STREAM|syscall.SOCK_CLOEXEC, 0)
	if err != nil {
		return nil, nil, err
	}
	return os.NewFile(uintptr(fds[1]), "parent"), os.NewFile(uintptr(fds[0]), "child"), nil
}
开发者ID:mheon,项目名称:runc,代码行数:7,代码来源:container_linux.go

示例4: newSocketPair

func newSocketPair(name string) (*os.File, *os.File, error) {
	pair, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
	if err != nil {
		return nil, nil, err
	}
	return os.NewFile(uintptr(pair[0]), name), os.NewFile(uintptr(pair[1]), name), nil
}
开发者ID:ably-forks,项目名称:flynn,代码行数:7,代码来源:init.go

示例5: socketPair

func socketPair() (sock1 *os.File, sock2 *os.File, err error) {
	var fds [2]int
	fds, err = syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_STREAM, 0)
	if err != nil {
		fmt.Println(err.Error())
	}
	return os.NewFile(uintptr(fds[0]), "|0"), os.NewFile(uintptr(fds[1]), "|1"), err
}
开发者ID:jonpugh,项目名称:maggiefs,代码行数:8,代码来源:transfer_test.go

示例6: mount

func mount(dir string, ready chan<- struct{}, errp *error) (fusefd *os.File, err error) {
	// linux mount is never delayed
	close(ready)

	fds, err := syscall.Socketpair(syscall.AF_FILE, syscall.SOCK_STREAM, 0)
	if err != nil {
		return nil, fmt.Errorf("socketpair error: %v", err)
	}
	defer syscall.Close(fds[0])
	defer syscall.Close(fds[1])

	cmd := exec.Command("fusermount", "--", dir)
	cmd.Env = append(os.Environ(), "_FUSE_COMMFD=3")

	writeFile := os.NewFile(uintptr(fds[0]), "fusermount-child-writes")
	defer writeFile.Close()
	cmd.ExtraFiles = []*os.File{writeFile}

	out, err := cmd.CombinedOutput()
	if len(out) > 0 || err != nil {
		return nil, fmt.Errorf("fusermount: %q, %v", out, err)
	}

	readFile := os.NewFile(uintptr(fds[1]), "fusermount-parent-reads")
	defer readFile.Close()
	c, err := net.FileConn(readFile)
	if err != nil {
		return nil, fmt.Errorf("FileConn from fusermount socket: %v", err)
	}
	defer c.Close()

	uc, ok := c.(*net.UnixConn)
	if !ok {
		return nil, fmt.Errorf("unexpected FileConn type; expected UnixConn, got %T", c)
	}

	buf := make([]byte, 32) // expect 1 byte
	oob := make([]byte, 32) // expect 24 bytes
	_, oobn, _, _, err := uc.ReadMsgUnix(buf, oob)
	scms, err := syscall.ParseSocketControlMessage(oob[:oobn])
	if err != nil {
		return nil, fmt.Errorf("ParseSocketControlMessage: %v", err)
	}
	if len(scms) != 1 {
		return nil, fmt.Errorf("expected 1 SocketControlMessage; got scms = %#v", scms)
	}
	scm := scms[0]
	gotFds, err := syscall.ParseUnixRights(&scm)
	if err != nil {
		return nil, fmt.Errorf("syscall.ParseUnixRights: %v", err)
	}
	if len(gotFds) != 1 {
		return nil, fmt.Errorf("wanted 1 fd; got %#v", gotFds)
	}
	f := os.NewFile(uintptr(gotFds[0]), "/dev/fuse")
	return f, nil
}
开发者ID:chengguozhen,项目名称:clive,代码行数:57,代码来源:mount_linux.go

示例7: newCtlSockets

func newCtlSockets() (*os.File, *os.File, error) {
	fds, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_SEQPACKET, 0)
	if err != nil {
		return nil, nil, err
	}

	f1 := os.NewFile(uintptr(fds[0]), "ctl")
	f2 := os.NewFile(uintptr(fds[1]), "ctl")
	return f1, f2, nil
}
开发者ID:RubanDeventhiran,项目名称:rudder,代码行数:10,代码来源:cproxy.go

示例8: Socketpair

func (k *PosixKernel) Socketpair(domain, typ, proto int, vector co.Obuf) uint64 {
	pair, err := syscall.Socketpair(domain, typ, proto)
	if err != nil {
		return Errno(err)
	}
	if err := vector.Pack(pair); err != nil {
		return UINT64_MAX // FIXME
	}
	return 0
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:10,代码来源:socket.go

示例9: unixgramSocketpair

func unixgramSocketpair() (l, r *os.File, err error) {
	fd, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_SEQPACKET, 0)
	if err != nil {
		return nil, nil, os.NewSyscallError("socketpair",
			err.(syscall.Errno))
	}
	l = os.NewFile(uintptr(fd[0]), "socketpair-half1")
	r = os.NewFile(uintptr(fd[1]), "socketpair-half2")
	return
}
开发者ID:JeremyOT,项目名称:go-fuse,代码行数:10,代码来源:mount_linux.go

示例10: init

func (sp *SocketPair) init() {
	fds, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)

	if err != nil {
		fmt.Println(err)
		return
	}
	sp.LocalFile = os.NewFile(uintptr(fds[0]), "sp-0")
	sp.RemoteFile = os.NewFile(uintptr(fds[1]), "sp-1")

}
开发者ID:nickjenkin,项目名称:go-ipc,代码行数:11,代码来源:socketpair.go

示例11: Socketpair

func Socketpair(typ int) (a, b *os.File, err error) {
	fd, err := syscall.Socketpair(syscall.AF_UNIX, typ, 0)
	if err != nil {
		e := os.NewSyscallError("socketpair", err.(syscall.Errno))
		return nil, nil, e
	}

	a = FdToFile(fd[0], "socketpair-a")
	b = FdToFile(fd[1], "socketpair-b")
	return
}
开发者ID:rschmukler,项目名称:zeus,代码行数:11,代码来源:unixsocket.go

示例12: startProcessNotifier

// Gets a channel on which to publish events.
//
// Returns a file on which the process is supposed to write data, which then
// translate into these events.
func startProcessNotifier(ready chan<- bool) (w *os.File, err error) {
	fds, err := syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_DGRAM, 0)
	if err != nil {
		return
	}
	r := os.NewFile(uintptr(fds[0]), "notify:r") // File name is arbitrary
	w = os.NewFile(uintptr(fds[1]), "notify:w")

	go runProcessNotifier(r, ready)

	return w, nil
}
开发者ID:hannesg,项目名称:crank,代码行数:16,代码来源:process_notifier.go

示例13: NewSyncPipe

func NewSyncPipe() (s *SyncPipe, err error) {
	s = &SyncPipe{}

	fds, err := syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_STREAM|syscall.SOCK_CLOEXEC, 0)
	if err != nil {
		return nil, err
	}

	s.child = os.NewFile(uintptr(fds[0]), "child syncpipe")
	s.parent = os.NewFile(uintptr(fds[1]), "parent syncpipe")

	return s, nil
}
开发者ID:BreezeWu,项目名称:docker,代码行数:13,代码来源:sync_pipe_linux.go

示例14: createStreamMessage

func createStreamMessage(stream *spdystream.Stream, mode int, streamChans streamChanProvider, ret libchan.Sender) (*libchan.Message, error) {
	dataString := stream.Headers()["Data"]
	if len(dataString) != 1 {
		if len(dataString) == 0 {
			return nil, fmt.Errorf("Stream(%s) is missing data header", stream)
		} else {
			return nil, fmt.Errorf("Stream(%s) has multiple data headers", stream)
		}
	}

	data, decodeErr := base64.URLEncoding.DecodeString(dataString[0])
	if decodeErr != nil {
		return nil, decodeErr
	}

	var attach *os.File
	if !stream.IsFinished() {
		socketFds, socketErr := syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_STREAM|syscall.FD_CLOEXEC, 0)
		if socketErr != nil {
			return nil, socketErr
		}
		attach = os.NewFile(uintptr(socketFds[0]), "")
		conn, connErr := net.FileConn(os.NewFile(uintptr(socketFds[1]), ""))
		if connErr != nil {
			return nil, connErr
		}

		go func() {
			io.Copy(conn, stream)
		}()
		go func() {
			io.Copy(stream, conn)
		}()
	}

	retSender := ret
	if retSender == nil || libchan.RetPipe.Equals(retSender) {
		retSender = &StreamSender{stream: stream, streamChans: streamChans}
	}

	if mode&libchan.Ret == 0 {
		retSender.Close()
	}

	return &libchan.Message{
		Data: data,
		Fd:   attach,
		Ret:  retSender,
	}, nil
}
开发者ID:nathanleclaire,项目名称:libchan,代码行数:50,代码来源:spdy.go

示例15: run

func (e *Executor) run() {
	stackState := e.runner.prog.getStack()
	stackOffset := len(e.runner.stack) - len(stackState)
	copy(e.runner.stack[stackOffset:], stackState)

	resumeResult := 0 // don't resume
	if len(stackState) > 0 {
		resumeResult = -1 // resume; return this value to snapshot function caller
	}

	fds, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_STREAM|syscall.SOCK_CLOEXEC, 0)
	if err != nil {
		return
	}

	done := make(chan struct{})

	defer func() {
		syscall.Close(fds[1])
		<-done
	}()

	go func() {
		defer close(done)
		e.slave(fds[0], e.sigs, e.printer, e.cont)
	}()

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	setRunArg(e.arg)

	globalsMemoryAddr := (*reflect.SliceHeader)(unsafe.Pointer(&e.runner.globalsMemory)).Data
	memoryAddr := globalsMemoryAddr + uintptr(e.runner.memoryOffset)
	growMemorySize := len(e.runner.globalsMemory) - e.runner.memoryOffset

	trap, memorySize, stackPtr := run(e.runner.prog.getText(), int(e.runner.memorySize), memoryAddr, uintptr(growMemorySize), e.runner.stack, stackOffset, resumeResult, fds[1])

	e.runner.memorySize = wasm.MemorySize(memorySize)
	e.runner.lastTrap = traps.Id(trap)
	e.runner.lastStackPtr = stackPtr

	if trap == 0 {
		e.result = getRunResult()
	} else {
		e.err = e.runner.lastTrap
	}
	return
}
开发者ID:tsavola,项目名称:wag,代码行数:49,代码来源:runner.go


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