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


Golang Usock.ReadFD方法代码示例

本文整理汇总了Golang中github.com/burke/zeus/go/unixsocket.Usock.ReadFD方法的典型用法代码示例。如果您正苦于以下问题:Golang Usock.ReadFD方法的具体用法?Golang Usock.ReadFD怎么用?Golang Usock.ReadFD使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/burke/zeus/go/unixsocket.Usock的用法示例。


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

示例1: StartSlaveMonitor

func StartSlaveMonitor(tree *ProcessTree, local *unixsocket.Usock, remote *os.File, quit chan bool) {
	monitor := &SlaveMonitor{tree}

	// We just want this unix socket to be a channel so we can select on it...
	registeringFds := make(chan int, 3)
	go func() {
		for {
			fd, err := local.ReadFD()
			if err != nil {
				fmt.Println(err)
			}
			registeringFds <- fd
		}
	}()

	for _, slave := range monitor.tree.SlavesByName {
		if slave.Parent == nil {
			go monitor.startInitialProcess(remote)
		} else {
			go monitor.bootSlave(slave)
		}
	}

	for {
		select {
		case <-quit:
			quit <- true
			monitor.cleanupChildren()
			return
		case fd := <-registeringFds:
			monitor.slaveDidBeginRegistration(fd)
		}
	}
}
开发者ID:Epictetus,项目名称:zeus,代码行数:34,代码来源:slavemonitor.go

示例2: receiveFileFromFD

func receiveFileFromFD(usock *unixsocket.Usock) (*os.File, error) {
	clientFd, err := usock.ReadFD()
	if err != nil {
		return nil, errors.New("Expected FD, none received!")
	}
	fileName := strconv.Itoa(rand.Int())
	return os.NewFile(uintptr(clientFd), fileName), nil
}
开发者ID:nevir,项目名称:zeus,代码行数:8,代码来源:clienthandler.go

示例3: receiveTTY

func receiveTTY(usock *unixsocket.Usock, err error) (*os.File, error) {
	if err != nil {
		return nil, err
	}

	clientFd, err := usock.ReadFD()
	if err != nil {
		return nil, errors.New("Expected FD, none received!")
	}
	fileName := strconv.Itoa(rand.Int())
	clientFile := unixsocket.FdToFile(clientFd, fileName)

	return clientFile, nil
}
开发者ID:honkfestival,项目名称:zeus,代码行数:14,代码来源:clienthandler.go

示例4: receiveCommandArgumentsAndPid

func receiveCommandArgumentsAndPid(usock *unixsocket.Usock, err error) (string, int, int, int, error) {
	if err != nil {
		return "", -1, -1, -1, err
	}

	msg, err := usock.ReadMessage()
	if err != nil {
		return "", -1, -1, -1, err
	}

	argCount, clientPid, command, err := messages.ParseClientCommandRequestMessage(msg)
	if err != nil {
		return "", -1, -1, -1, err
	}

	argFD, err := usock.ReadFD()
	return command, clientPid, argCount, argFD, err
}
开发者ID:nevir,项目名称:zeus,代码行数:18,代码来源:clienthandler.go

示例5: handleClientConnection

// see docs/client_master_handshake.md
func handleClientConnection(tree *ProcessTree, usock *unixsocket.Usock) {
	defer usock.Close()

	// we have established first contact to the client.

	// we first read the command and arguments specified from the connection. (step 1)
	msg, err := usock.ReadMessage()
	if err != nil {
		fmt.Println(err)
		return
	}
	command, arguments, err := ParseClientCommandRequestMessage(msg)
	if err != nil {
		fmt.Println(err)
		return
	}

	commandNode := tree.FindCommand(command)
	if commandNode == nil {
		fmt.Println("ERROR: Node not found!: ", command)
		return
	}
	command = commandNode.Name // resolve aliases
	slaveNode := commandNode.Parent

	// Now we read the terminal IO socket to use for raw IO (step 2)
	clientFd, err := usock.ReadFD()
	if err != nil {
		fmt.Println("Expected FD, none received!")
		return
	}
	fileName := strconv.Itoa(rand.Int())
	clientFile := unixsocket.FdToFile(clientFd, fileName)
	defer clientFile.Close()

	// We now need to fork a new command process.
	// For now, we naively assume it's running...

	if slaveNode.Error != "" {
		// we can skip steps 3-5 as they deal with the command process we're not spawning.
		// Write a fake pid (step 6)
		usock.WriteMessage("0")
		// Write the error message to the terminal
		clientFile.Write([]byte(slaveNode.Error))
		// Skip step 7, and write an exit code to the client (step 8)
		usock.WriteMessage("1")
		return
	}

	// boot a command process and establish a socket connection to it.
	slaveNode.WaitUntilBooted()

	msg = CreateSpawnCommandMessage(command)
	slaveNode.mu.Lock()
	slaveNode.Socket.Write([]byte(msg))
	slaveNode.mu.Unlock()

	// TODO: deadline? how to respond if this is never sent?
	commandFd := <-slaveNode.ClientCommandPTYFileDescriptor
	if err != nil {
		fmt.Println("Couldn't start command process!", err)
	}
	fileName = strconv.Itoa(rand.Int())
	commandFile := unixsocket.FdToFile(commandFd, fileName)
	defer commandFile.Close()

	// Send the arguments to the command process (step 3)
	commandFile.Write([]byte(arguments)) // TODO: What if they're too long?

	commandSocket, err := unixsocket.MakeUnixSocket(commandFile)
	if err != nil {
		fmt.Println("MakeUnixSocket", err)
	}
	defer commandSocket.Close()

	// Send the client terminal connection to the command process (step 4)
	commandUsock := unixsocket.NewUsock(commandSocket)
	commandUsock.WriteFD(clientFd)

	// Receive the pid from the command process (step 5)
	msg, err = commandUsock.ReadMessage()
	if err != nil {
		println(err)
	}
	intPid, _, _ := ParsePidMessage(msg)

	// Send the pid to the client process (step 6)
	strPid := strconv.Itoa(intPid)
	usock.WriteMessage(strPid)

	// Receive the exit status from the command (step 7)
	msg, err = commandUsock.ReadMessage()
	if err != nil {
		println(err)
	}

	// Forward the exit status to the Client (step 8)
	usock.WriteMessage(msg)

//.........这里部分代码省略.........
开发者ID:Epictetus,项目名称:zeus,代码行数:101,代码来源:clienthandler.go


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