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


Golang net.UnixListener类代码示例

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


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

示例1: accept

// listen for gui client to connect to our socket
func accept(listener *net.UnixListener, ch chan []byte) {
	for {
		// we are going to eat the serial data until
		// we get a socket connection so we don't block the channel
		select {
		case <-ch:
			log.Println("eating serial data")
		default:
		}

		// set timeout to fall through so we can check the channel for
		// serial data
		listener.SetDeadline(time.Now().Add(100 * time.Millisecond))
		conn, err := listener.AcceptUnix()
		if nil != err {
			if opErr, ok := err.(*net.OpError); ok && opErr.Timeout() {
				continue
			}
			log.Println(err)
		} else {
			// we have connection, call handle, we only handle one connection
			// so no goroutine here
			handleSocket(conn, ch)
		}
	}
}
开发者ID:jmore-reachtech,项目名称:io,代码行数:27,代码来源:sio.go

示例2: NewServerFromListener

// NewServerFromListener creates a server struct using a UnixListener specified
// by ln. cb is the callback function which will get called for any authentication
// request.
func NewServerFromListener(ln *net.UnixListener, cb AuthCB) (s *Server, err error) {
	s = &Server{}
	s.sockPath = ln.Addr().String()
	s.cb = cb
	s.ln = net.Listener(ln)
	return
}
开发者ID:whawty,项目名称:auth,代码行数:10,代码来源:sasl.go

示例3: 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

示例4: 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

示例5: acceptConnections

func acceptConnections(in chan net.Conn, listener *net.UnixListener) {
	for {
		c, err := listener.Accept()
		if err != nil {
			panic(err.String())
		}
		in <- c
	}
}
开发者ID:kij,项目名称:gocode,代码行数:9,代码来源:server.go

示例6: connListener

func connListener(conn chan net.Conn, listener *net.UnixListener) {
	for {
		c, err := listener.Accept()
		if err != nil {
			panic("Accept: ", err.String())
		}
		conn <- c
	}
}
开发者ID:royger,项目名称:DAD,代码行数:9,代码来源:server.go

示例7: 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

示例8: Accept

func (us *UnixSock) Accept(l *net.UnixListener) {
	// Why doesn't this get called on ctrl + c
	defer l.Close()

	for {
		fd, err := l.Accept()
		if err != nil {
			break
		}
		us.processBuffer(fd)
	}
}
开发者ID:pquerna,项目名称:streamplay,代码行数:12,代码来源:unixsock.go

示例9: 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

示例10: runSaslAuthSocketListener

func runSaslAuthSocketListener(listener *net.UnixListener, store *StoreChan) error {
	path := listener.Addr().String()
	s, err := sasl.NewServerFromListener(listener, func(log string, pwd string, srv string, rlm string) (bool, string, error) {
		return callback(log, pwd, srv, rlm, path, store)
	})
	if err != nil {
		return err
	}
	wl.Printf("listening on '%s'", path)

	if err := s.Run(); err != nil {
		wl.Printf("error on sasl socket '%s': %s", path, err)
	}
	return nil
}
开发者ID:whawty,项目名称:auth,代码行数:15,代码来源:sasl_socket.go

示例11: lstn

func (e *Euclid) lstn(l *net.UnixListener, loop *loop) {
	for {
		conn, err := l.AcceptUnix()
		if err != nil {
			panic(err)
		}
		var buf [1024]byte
		n, err := conn.Read(buf[:])
		if err != nil {
			panic(err)
		}
		r := bytes.Trim(buf[:n], " ")
		resp := e.processMsg(r, loop.comm)
		conn.Write(resp)
		conn.Close()
	}
}
开发者ID:wSCP,项目名称:scpwm-old,代码行数:17,代码来源:euclid.go

示例12: run

func (srv *Server) run(listener *net.UnixListener) {
	defer os.Remove(SOCKET)

	for {
		conn, err := listener.AcceptUnix()
		if err != nil {
			select {
			case srv.errors <- err:
			case <-srv.closed:
			}
			break
		}

		go srv.handleConn(conn)
	}

	close(srv.finished)
}
开发者ID:bboreham,项目名称:ambergris,代码行数:18,代码来源:server.go

示例13: handleUnixConnection

func handleUnixConnection(listener *net.UnixListener, unix UnixHandler) {
	for {
		data := make([]byte, 512)
		conn, err := listener.AcceptUnix()
		if err != nil {
			fmt.Println(err)
			continue
		}
		read_length, err := conn.Read(data[0:])
		if err != nil { // EOF, or worse
			fmt.Println(err)
			continue
		}
		if read_length > 0 {
			go panicWrapping(func() {
				unix.UnixReceived(data[0:read_length], conn)
			})
		}
	}
}
开发者ID:trigrass2,项目名称:sntp,代码行数:20,代码来源:reactor.go

示例14: Serve

// Serve listens on sock for new connections and services them.
func (server LinuxHostAdminServer) Serve(sock *net.UnixListener) error {
	// Set the socket to allow peer credentials to be passed
	err := NewAuthenticatedFileSocket(sock)
	if err != nil {
		return err
	}

	connections := make(chan *net.UnixConn, 1)
	errors := make(chan error, 1)
	go func() {
		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 s.ServeCodec(protorpc.NewServerCodec(oob))
	}
}
开发者ID:tmroeder,项目名称:cloudproxy,代码行数:40,代码来源:linux_host_admin_rpc.go

示例15: Run

// Run the server's accept loop, waiting for connections from l.
// Correct shutdown procedure is:
// set slots to a number such that no new processes will run
// wait for all running processes to finish
// set shittingDown to true
// close the listening socket
func Run(v *viper.Viper, l *net.UnixListener) {
	i := newInstance(v)
	i.listener = l
	for {
		c, err := l.AcceptUnix()
		i.m.Lock()
		sdc := i.shutdownComplete
		i.m.Unlock()
		if sdc {
			glog.Infoln("Shutdown complete. closing listener.")
			if c != nil {
				c.Close()
			}
			l.Close()
			return
		} else if err != nil {
			glog.Errorln("Accept() failed on unix socket:", err)
			return
		}
		go i.connectionHandler(c)
	}
}
开发者ID:akramer,项目名称:lateral,代码行数:28,代码来源:server.go


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