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


Golang UDPConn.File方法代碼示例

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


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

示例1: getFile

func getFile(conn *net.UDPConn) *os.File {
	file, err := conn.File()
	if err != nil {
		log.Fatal(err)
	}
	return file
}
開發者ID:Kaign,項目名稱:benchs,代碼行數:7,代碼來源:udpbenchs_test.go

示例2: getUDPSocketName

func getUDPSocketName(conn *net.UDPConn) (syscall.Sockaddr, error) {
	file, err := conn.File()
	if err != nil {
		return nil, err
	}
	return syscall.Getsockname(int(file.Fd()))
}
開發者ID:Clarifai,項目名稱:kubernetes,代碼行數:7,代碼來源:udp_linux.go

示例3: setUDPSocketOptions6

// setUDPSocketOptions6 prepares the v6 socket for sessions.
func setUDPSocketOptions6(conn *net.UDPConn) error {
	file, err := conn.File()
	if err != nil {
		return err
	}
	if err := syscall.SetsockoptInt(int(file.Fd()), syscall.IPPROTO_IPV6, syscall.IPV6_RECVPKTINFO, 1); err != nil {
		return err
	}
	return nil
}
開發者ID:Clarifai,項目名稱:kubernetes,代碼行數:11,代碼來源:udp_linux.go

示例4: getUDPSocketOptions6Only

// getUDPSocketOption6Only return true if the socket is v6 only and false when it is v4/v6 combined
// (dualstack).
func getUDPSocketOptions6Only(conn *net.UDPConn) (bool, error) {
	file, err := conn.File()
	if err != nil {
		return false, err
	}
	// dual stack. See http://stackoverflow.com/questions/1618240/how-to-support-both-ipv4-and-ipv6-connections
	v6only, err := syscall.GetsockoptInt(int(file.Fd()), syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY)
	if err != nil {
		return false, err
	}
	return v6only == 1, nil
}
開發者ID:Clarifai,項目名稱:kubernetes,代碼行數:14,代碼來源:udp_linux.go

示例5: SetMulticastLoopback

// SetMulticastLoopback turns on or off multicast loopbacks on the interface the connection is on.
func SetMulticastLoopback(conn *net.UDPConn, ipversion int, v bool) error {
	file, err := conn.File()
	if err != nil {
		return err
	}
	fd := int(file.Fd())
	switch ipversion {
	default:
		return setIPv4MulticastLoopback(fd, v)
	case 6:
		return setIPv6MulticastLoopback(fd, v)
	}
}
開發者ID:jhahn21,項目名稱:go-mdns-sd,代碼行數:14,代碼來源:ipaux.go

示例6: setUDPSocketOptions4

// setUDPSocketOptions4 prepares the v4 socket for sessions.
func setUDPSocketOptions4(conn *net.UDPConn) error {
	file, err := conn.File()
	if err != nil {
		return err
	}
	if err := syscall.SetsockoptInt(int(file.Fd()), syscall.IPPROTO_IP, syscall.IP_PKTINFO, 1); err != nil {
		return err
	}
	// Calling File() above results in the connection becoming blocking, we must fix that.
	// See https://github.com/miekg/dns/issues/279
	err = syscall.SetNonblock(int(file.Fd()), true)
	if err != nil {
		return err
	}
	return nil
}
開發者ID:2722,項目名稱:lantern,代碼行數:17,代碼來源:udp_linux.go

示例7: runCProxy

func runCProxy(tun *os.File, conn *net.UDPConn, ctl *os.File, tunIP ip.IP4, tunMTU int) {
	var log_errors int
	if log.V(1) {
		log_errors = 1
	}

	c, err := conn.File()
	if err != nil {
		log.Error("Converting UDPConn to File failed: ", err)
		return
	}
	defer c.Close()

	C.run_proxy(
		C.int(tun.Fd()),
		C.int(c.Fd()),
		C.int(ctl.Fd()),
		C.in_addr_t(tunIP.NetworkOrder()),
		C.size_t(tunMTU),
		C.int(log_errors),
	)
}
開發者ID:hingstarne,項目名稱:flannel,代碼行數:22,代碼來源:cproxy.go

示例8: SetMulticastTTL

// SetMulticastTTL sets the TTL on packets from this connection.
func SetMulticastTTL(conn *net.UDPConn, ipversion int, v int) error {
	var proto, opt int
	switch ipversion {
	default:
		proto = syscall.IPPROTO_IP
		opt = syscall.IP_MULTICAST_TTL
	case 6:
		proto = syscall.IPPROTO_IPV6
		opt = syscall.IPV6_MULTICAST_HOPS
	}
	if file, err := conn.File(); err == nil {
		fd := int(file.Fd())
		err := syscall.SetsockoptInt(fd, proto, opt, v)
		if err != nil {
			return os.NewSyscallError("setsockopt", err)
		}
		file.Close()
	} else {
		return err
	}
	return nil
}
開發者ID:jhahn21,項目名稱:go-mdns-sd,代碼行數:23,代碼來源:ipaux.go

示例9: handleUDP

func handleUDP(udpConn *net.UDPConn, addr string) {
	log.Printf("serving SIP on UDP %s", addr)

	if _, err := udpConn.File(); err != nil {
		log.Printf("handleUDP: unable to set UDP connection to blocking: %s", err)
	}

	for {
		/*
			rfc3261 18.1.1 Sending Requests
			However implementations MUST be able to handle messages up to the maximum
			datagram packet size.  For UDP, this size is 65,535 bytes, including
			IP and UDP headers.
		*/
		buf := make([]byte, 66536)
		n, addr, err := udpConn.ReadFromUDP(buf)
		if err != nil {
			log.Printf("ReadFromUDP: %s", err)
		}

		log.Printf("ReadFromUDP: %d bytes from %s", n, addr)
		parseSIP(string(buf[:n]))
	}
}
開發者ID:udhos,項目名稱:sipswitchd,代碼行數:24,代碼來源:sipswitchd.go

示例10: fastProxy

func fastProxy(sm *subnet.SubnetManager, tun *os.File, conn *net.UDPConn, tunIP ip.IP4, tunMTU uint, port int) {
	log.Info("Running fast proxy loop")

	c, err := conn.File()
	if err != nil {
		log.Error("Converting UDPConn to File failed: ", err)
		return
	}
	defer c.Close()

	ctl, peerCtl, err := newCtlSockets()
	if err != nil {
		log.Error("Failed to create control socket: ", err)
		return
	}
	defer ctl.Close()
	defer peerCtl.Close()

	go runCProxy(tun, c, peerCtl, tunIP, tunMTU)

	log.Info("Watching for new subnet leases")
	evts := make(chan subnet.EventBatch)
	sm.Start(evts)

	for evtBatch := range evts {
		for _, evt := range evtBatch {
			if evt.Type == subnet.SubnetAdded {
				log.Info("Subnet added: ", evt.Lease.Network)
				var attrs subnet.BaseAttrs
				if err := json.Unmarshal([]byte(evt.Lease.Data), &attrs); err != nil {
					log.Error("Error decoding subnet lease JSON: ", err)
					continue
				}

				cmd := C.command{
					cmd:           C.CMD_SET_ROUTE,
					dest_net:      C.in_addr_t(evt.Lease.Network.IP.NetworkOrder()),
					dest_net_len:  C.int(evt.Lease.Network.PrefixLen),
					next_hop_ip:   C.in_addr_t(attrs.PublicIP.NetworkOrder()),
					next_hop_port: C.short(port),
				}

				writeCommand(ctl, &cmd)

			} else if evt.Type == subnet.SubnetRemoved {
				log.Info("Subnet removed: ", evt.Lease.Network)

				cmd := C.command{
					cmd:          C.CMD_DEL_ROUTE,
					dest_net:     C.in_addr_t(evt.Lease.Network.IP.NetworkOrder()),
					dest_net_len: C.int(evt.Lease.Network.PrefixLen),
				}

				writeCommand(ctl, &cmd)

			} else {
				log.Error("Internal error: unknown event type: ", int(evt.Type))
			}
		}
	}
}
開發者ID:RubanDeventhiran,項目名稱:rudder,代碼行數:61,代碼來源:cproxy.go


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