示例#1
0
// NewTCPSocket creates a TCP socket listener with the specified address and
// and the specified tls configuration. If TLSConfig is set, will encapsulate the
// TCP listener inside a TLS one.
// The channel passed is used to activate the listenbuffer when the caller is ready
// to accept connections.
func NewTCPSocket(addr string, tlsConfig *tls.Config, activate <-chan struct{}) (net.Listener, error) {
	l, err := listenbuffer.NewListenBuffer("tcp", addr, activate)
	if err != nil {
		return nil, err
	}
	if tlsConfig != nil {
		tlsConfig.NextProtos = []string{"http/1.1"}
		l = tls.NewListener(l, tlsConfig)
	}
	return l, nil
}
示例#2
0
// NewUnixSocket creates a unix socket with the specified path and group.
// The channel passed is used to activate the listenbuffer when the caller is ready
// to accept connections.
func NewUnixSocket(path, group string, activate <-chan struct{}) (net.Listener, error) {
	if err := syscall.Unlink(path); err != nil && !os.IsNotExist(err) {
		return nil, err
	}
	mask := syscall.Umask(0777)
	defer syscall.Umask(mask)
	l, err := listenbuffer.NewListenBuffer("unix", path, activate)
	if err != nil {
		return nil, err
	}
	if err := setSocketGroup(path, group); err != nil {
		l.Close()
		return nil, err
	}
	if err := os.Chmod(path, 0660); err != nil {
		l.Close()
		return nil, err
	}
	return l, nil
}
示例#3
0
func NewTCPSocketNoTls(addr string, activate <-chan struct{}) (net.Listener, error) {
	fmt.Println(addr)
	l, err := listenbuffer.NewListenBuffer("tcp", addr, activate)
	fmt.Println(l)

	if err != nil {
		return nil, err
	}

	//	if tlsConfig != nil {
	//		tlsConfig.NextProtos = []string{"http/1.1"}
	//		l = tls.NewListener(l, tlsConfig)
	//	}

	//	ln, err := Listen("tcp", "127.0.0.1:0")
	//	if err != nil {
	//		if ln, err = Listen("tcp6", "[::1]:0"); err != nil {
	//			t.Fatalf("ListenTCP on :0: %v", err)
	//		}
	//	}

	return l, nil
}