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


Golang net.UnknownNetworkError函數代碼示例

本文整理匯總了Golang中net.UnknownNetworkError函數的典型用法代碼示例。如果您正苦於以下問題:Golang UnknownNetworkError函數的具體用法?Golang UnknownNetworkError怎麽用?Golang UnknownNetworkError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: default_dialer

func default_dialer(proto, laddr, raddr string, timeout time.Duration) (net.Conn, error) {
	if proto == "" {
		if strings.IndexRune(raddr, ':') != -1 {
			proto = "tcp"
		} else {
			proto = "unix"
		}
	}

	// Make a connection
	d := &net.Dialer{Timeout: timeout}
	if laddr != "" {
		var err error
		switch proto {
		case "tcp", "tcp4", "tcp6":
			d.LocalAddr, err = net.ResolveTCPAddr(proto, laddr)
		case "unix":
			d.LocalAddr, err = net.ResolveTCPAddr(proto, laddr)
		default:
			err = net.UnknownNetworkError(proto)
		}
		if err != nil {
			return nil, err
		}
	}
	return d.Dial(proto, raddr)
}
開發者ID:hurricane1026,項目名稱:highway,代碼行數:27,代碼來源:backconnpool.go

示例2: ResolveAddr

func ResolveAddr(network, addr string) (net.Addr, error) {
	resolver := resolvers[network]
	if resolver == nil {
		return nil, net.UnknownNetworkError(network)
	}

	return resolver(addr)
}
開發者ID:utamaro,項目名稱:gogotelehash,代碼行數:8,代碼來源:registry.go

示例3: Read

func (cn *badConn) Read([]byte) (int, error) {
	if cn.readDelay != 0 {
		time.Sleep(cn.readDelay)
	}
	if cn.readErr != nil {
		return 0, cn.readErr
	}
	return 0, net.UnknownNetworkError("badConn")
}
開發者ID:jameswei,項目名稱:kingtask,代碼行數:9,代碼來源:main_test.go

示例4: Write

func (cn *badConn) Write([]byte) (int, error) {
	if cn.writeDelay != 0 {
		time.Sleep(cn.writeDelay)
	}
	if cn.writeErr != nil {
		return 0, cn.writeErr
	}
	return 0, net.UnknownNetworkError("badConn")
}
開發者ID:jameswei,項目名稱:kingtask,代碼行數:9,代碼來源:main_test.go

示例5: getConnection

// get a new connection using the specified transport.
func (f *Fluent) getConnection() (net.Conn, error) {
	switch f.Config.FluentNetwork {
	case "tcp":
		return net.DialTimeout(f.Config.FluentNetwork, f.Config.FluentHost+":"+strconv.Itoa(f.Config.FluentPort), f.Config.Timeout)
	case "unix":
		return net.DialTimeout(f.Config.FluentNetwork, f.Config.FluentSocketPath, f.Config.Timeout)
	default:
		return nil, net.UnknownNetworkError(f.Config.FluentNetwork)
	}
}
開發者ID:bluele,項目名稱:fluent-logger-golang,代碼行數:11,代碼來源:fluent.go

示例6: Dial

func (a *peerAddr) Dial(e *e3x.Endpoint, x *e3x.Exchange) (net.Conn, error) {
	mod, _ := FromEndpoint(e).(*module)
	if mod == nil {
		return nil, net.UnknownNetworkError("unable to bridge")
	}

	router := e.GetExchange(a.router)
	if router == nil {
		return nil, net.UnknownNetworkError("unable to bridge")
	}

	conn := newConnection(x.RemoteHashname(), a, router, func() {
		mod.unregisterConnection(router, x.LocalToken())
	})

	mod.registerConnection(router, x.LocalToken(), conn)

	return conn, nil
}
開發者ID:utamaro,項目名稱:gogotelehash,代碼行數:19,代碼來源:net_addr.go

示例7: connect

// connect establishes a new connection using the specified transport.
func (f *Fluent) connect() (err error) {
	switch f.Config.FluentNetwork {
	case "tcp":
		f.conn, err = net.DialTimeout(f.Config.FluentNetwork, f.Config.FluentHost+":"+strconv.Itoa(f.Config.FluentPort), f.Config.Timeout)
	case "unix":
		f.conn, err = net.DialTimeout(f.Config.FluentNetwork, f.Config.FluentSocketPath, f.Config.Timeout)
	default:
		err = net.UnknownNetworkError(f.Config.FluentNetwork)
	}
	return
}
開發者ID:gmelika,項目名稱:rack,代碼行數:12,代碼來源:fluent.go

示例8: dialMulti

func (d *Dialer) dialMulti(network, address string, ips []net.IP, port string) (conn net.Conn, err error) {
	if d.Level <= 1 || len(ips) == 1 {
		for i, ip := range ips {
			addr := net.JoinHostPort(ip.String(), port)
			conn, err := d.Dialer.Dial(network, addr)
			if err != nil {
				if i < len(ips)-1 {
					continue
				} else {
					return nil, err
				}
			}
			return conn, nil
		}
	} else {
		type racer struct {
			c net.Conn
			e error
		}

		level := len(ips)
		if level > d.Level {
			level = d.Level
			ips = ips[:level]
		}

		lane := make(chan racer, level)
		for i := 0; i < level; i++ {
			go func(addr string, c chan<- racer) {
				conn, err := d.Dialer.Dial(network, addr)
				lane <- racer{conn, err}
			}(net.JoinHostPort(ips[i].String(), port), lane)
		}

		var r racer
		for j := 0; j < level; j++ {
			r = <-lane
			if r.e == nil {
				go func(count int) {
					var r1 racer
					for ; count > 0; count-- {
						r1 = <-lane
						if r1.c != nil {
							r1.c.Close()
						}
					}
				}(level - 1 - j)
				return r.c, nil
			}
		}
	}

	return nil, net.UnknownNetworkError("Unkown transport/direct error")
}
開發者ID:johnsonz,項目名稱:goproxy,代碼行數:54,代碼來源:dialer.go

示例9: Read

func (c *ConnMock) Read(b []byte) (n int, err error) {
	if c.ReturnTimeout {
		return 0, net.UnknownNetworkError("i/o timeout")
	}
	if c.ReadData != nil {
		l := copy(b, c.ReadData)
		c.ReadData = nil
		return l, nil
	}
	return 0, io.EOF
}
開發者ID:cezarsa,項目名稱:go-syslog,代碼行數:11,代碼來源:server_test.go

示例10: utp2udp

func utp2udp(n string) (string, error) {
	switch n {
	case "utp":
		return "udp", nil
	case "utp4":
		return "udp4", nil
	case "utp6":
		return "udp6", nil
	default:
		return "", net.UnknownNetworkError(n)
	}
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數:12,代碼來源:addr.go

示例11: ResolveAddr

func ResolveAddr(network, address string) (net.Addr, error) {
	switch network {
	default:
		return nil, net.UnknownNetworkError(network)
	case "ip", "ip4", "ip6":
		return net.ResolveIPAddr(network, address)
	case "tcp", "tcp4", "tcp6":
		return net.ResolveTCPAddr(network, address)
	case "udp", "udp4", "udp6":
		return net.ResolveUDPAddr(network, address)
	case "unix", "unixgram", "unixpacket":
		return net.ResolveUnixAddr(network, address)
	}
}
開發者ID:andradeandrey,項目名稱:go-ipfs,代碼行數:14,代碼來源:addr.go

示例12: getTestErrors

func getTestErrors() testErrors {
	errs := testErrors{
		Busy:       ErrServerBusy,
		Declined:   ErrChannelClosed,
		Timeout:    ErrTimeout,
		Network:    NewSystemError(ErrCodeNetwork, "fake network error"),
		Connection: net.UnknownNetworkError("fake connection error"),
		BadRequest: ErrTimeoutRequired,
		Unexpected: NewSystemError(ErrCodeUnexpected, "fake unexpected error"),
		Cancelled:  NewSystemError(ErrCodeCancelled, "fake cancelled error"),
	}
	errs.all = []error{errs.Busy, errs.Declined, errs.Timeout, errs.Network, errs.Connection,
		errs.BadRequest, errs.Unexpected, errs.Cancelled}
	return errs
}
開發者ID:uber,項目名稱:tchannel-go,代碼行數:15,代碼來源:retry_test.go

示例13: NewDefaultHealthChecker

// NewDefaultHealthChecker returns an instance of the default health checker
// algorithm. The default health checker tries to do a simple connection to the
// server. If the connection is successful the health check pass, otherwise it
// fails with an error. Possible proto values are tcp or udp.
func NewDefaultHealthChecker() HealthChecker {
	return HealthCheckerFunc(func(target string, port uint16, proto string) (ok bool, err error) {
		address := fmt.Sprintf("%s:%d", target, port)
		if proto != "tcp" && proto != "udp" {
			return false, net.UnknownNetworkError(proto)
		}

		conn, err := net.Dial(proto, address)
		if err != nil {
			return false, err
		}
		conn.Close()
		return true, nil
	})
}
開發者ID:rafaeljusto,項目名稱:dnsdisco,代碼行數:19,代碼來源:defaults.go

示例14: DialUDP

// DialUDP connects to the remote address raddr on the network net,
// which must be "udp", "udp4", or "udp6".  If laddr is not nil, it is used
// as the local address for the connection.
func DialUDP(netType string, laddr, raddr *net.UDPAddr) (c *net.UDPConn, err os.Error) {
	switch netType {
	case "udp", "udp4", "udp6":
	default:
		return nil, net.UnknownNetworkError(netType)
	}
	if raddr == nil {
		return nil, &net.OpError{"dial", "udp", nil, errMissingAddress}
	}
	fd, e := internetSocket(net, laddr.toAddr(), raddr.toAddr(), syscall.SOCK_DGRAM, 0, "dial", sockaddrToUDP)
	if e != nil {
		return nil, e
	}
	return newUDPConn(fd), nil
}
開發者ID:leepro,項目名稱:goplay,代碼行數:18,代碼來源:udpserve.go

示例15: ListenUDT

// ListenUDT listens for incoming UDT packets addressed to the local
// address laddr.  Net must be "udt", "udt4", or "udt6".  If laddr has
// a port of 0, ListenUDT will choose an available port.
// The LocalAddr method of the returned UDTConn can be used to
// discover the port.  The returned connection's ReadFrom and WriteTo
// methods can be used to receive and send UDT packets with per-packet
// addressing.
func ListenUDT(network string, laddr *UDTAddr) (*UDTListener, error) {
	switch network {
	case "udt", "udt4", "udt6":
	default:
		return nil, &net.OpError{Op: "listen", Net: network, Addr: laddr, Err: net.UnknownNetworkError(network)}
	}
	if laddr == nil {
		laddr = &UDTAddr{addr: &net.UDPAddr{}}
	}

	fdl, err := listenFD(laddr)
	if err != nil {
		return nil, err
	}
	return &UDTListener{fd: fdl}, nil
}
開發者ID:TilmanGriesel,項目名稱:go-udtwrapper,代碼行數:23,代碼來源:listen.go


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