當前位置: 首頁>>代碼示例>>Golang>>正文


Golang UnixListener.File方法代碼示例

本文整理匯總了Golang中net.UnixListener.File方法的典型用法代碼示例。如果您正苦於以下問題:Golang UnixListener.File方法的具體用法?Golang UnixListener.File怎麽用?Golang UnixListener.File使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.UnixListener的用法示例。


在下文中一共展示了UnixListener.File方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ListenFile

// Utility to open a tcp[46]? or fd
func ListenFile(rawurl string) (file *os.File, err error) {

	if socketMasterFd := os.Getenv("SOCKETMASTER_FD"); socketMasterFd != "" {
		os.Setenv("SOCKETMASTER_FD", "")
		rawurl = fmt.Sprintf("fd://%s", socketMasterFd)
	}

	u, err := url.Parse(rawurl)
	if err != nil {
		return
	}

	switch u.Scheme {
	case "fd":
		var fd uint64
		fd, err = strconv.ParseUint(u.Host, 10, 8)
		if err != nil {
			return
		}
		// NOTE: The name argument doesn't really matter apparently
		file = os.NewFile(uintptr(fd), fmt.Sprintf("fd://%d", fd))
	case "unix": //, "unixpacket", "unixgram":
		var laddr *net.UnixAddr
		var listener *net.UnixListener

		laddr, err = net.ResolveUnixAddr(u.Scheme, u.Path)
		if err != nil {
			return
		}

		listener, err = net.ListenUnix(u.Scheme, laddr)
		if err != nil {
			return
		}

		file, err = listener.File()
	case "tcp", "tcp4", "tcp6":
		var laddr *net.TCPAddr
		var listener *net.TCPListener

		laddr, err = net.ResolveTCPAddr(u.Scheme, u.Host)
		if err != nil {
			return
		}

		listener, err = net.ListenTCP(u.Scheme, laddr)
		if err != nil {
			return
		}

		// Closing the listener doesn't affect the file and reversely.
		// http://golang.org/pkg/net/#TCPListener.File
		file, err = listener.File()
	default:
		err = fmt.Errorf("Unsupported scheme: %s", u.Scheme)
	}

	return
}
開發者ID:sjltaylor,項目名稱:socketmaster,代碼行數:60,代碼來源:listen.go

示例2: NewAuthenticatedFileSocket

func NewAuthenticatedFileSocket(sock *net.UnixListener) error {
	sockFile, err := sock.File()
	if err != nil {
		return err
	}
	sockFile.Close()
	return nil
}
開發者ID:tmroeder,項目名稱:cloudproxy,代碼行數:8,代碼來源:linux_host_admin_rpc_darwin.go

示例3: NewAuthenticatedFileSocket

func NewAuthenticatedFileSocket(sock *net.UnixListener) error {
	sockFile, err := sock.File()
	if err != nil {
		return err
	}
	err = syscall.SetsockoptInt(int(sockFile.Fd()), syscall.SOL_SOCKET, syscall.SO_PASSCRED, 1)
	sockFile.Close()
	return err
}
開發者ID:tmroeder,項目名稱:cloudproxy,代碼行數:9,代碼來源:linux_host_admin_rpc_linux.go

示例4: Serve

// Serve listens on sock for new connections and services them.
func (server LinuxHostAdminServer) Serve(sock *net.UnixListener) error {
	defer RecoverTPMResources()
	// Set the socket to allow peer credentials to be passed
	sockFile, err := sock.File()
	if err != nil {
		return err
	}
	err = syscall.SetsockoptInt(int(sockFile.Fd()), syscall.SOL_SOCKET, syscall.SO_PASSCRED, 1 /* true */)
	sockFile.Close()
	if err != nil {
		return err
	}

	connections := make(chan *net.UnixConn, 1)
	errors := make(chan error, 1)
	go func() {
		defer RecoverTPMResources()
		for {
			conn, err := sock.AcceptUnix()
			if err != nil {
				errors <- err
				break
			}
			connections <- conn
		}
	}()

	for {
		var conn *net.UnixConn
		select {
		case conn = <-connections:
			break
		case err = <-errors:
			return err
		case <-server.Done:
			return nil
		}
		s := rpc.NewServer()
		oob := util.NewOOBUnixConn(conn)
		err = s.RegisterName("LinuxHost", linuxHostAdminServerStub{oob, server.lh, server.Done})
		if err != nil {
			return err
		}
		go func() {
			defer RecoverTPMResources()
			s.ServeCodec(protorpc.NewServerCodec(oob))
		}()
	}
}
開發者ID:kevinawalsh,項目名稱:cloudproxy,代碼行數:50,代碼來源:linux_host_admin_rpc.go


注:本文中的net.UnixListener.File方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。