当前位置: 首页>>代码示例>>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;未经允许,请勿转载。