From d82d6e2d96f137af2bbba96f974088e06985223d Mon Sep 17 00:00:00 2001 From: Kyle Xiao Date: Wed, 11 Mar 2026 14:59:21 +0800 Subject: [PATCH] chore: remove UDP support and unused future roadmap UDP was never implemented (listener returned ErrUnsupported, dialer was commented out). Remove all dead UDP code paths and return an explicit error for UDP networks in CreateListener. Also remove the Future roadmap section from READMEs as there is no plan to support these. --- README.md | 7 ------- README_CN.md | 7 ------- net_dialer.go | 1 - net_listener.go | 46 ++++++---------------------------------------- net_netfd.go | 5 ++--- net_sock.go | 18 +++++++++--------- 6 files changed, 17 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 340cad09..890ae067 100644 --- a/README.md +++ b/README.md @@ -53,12 +53,6 @@ For more information, please refer to [Document](#document). - TCP, Unix Domain Socket - Linux, macOS (operating system) -* **Future** - - [io_uring][io_uring] - - Shared Memory IPC - - TLS - - UDP - * **Unsupported** - Windows (operating system) @@ -100,4 +94,3 @@ More benchmarks reference [kitex-benchmark][kitex-benchmark] and [hertz-benchmar [LinkBuffer]: nocopy_linkbuffer.go [gopool]: https://github.com/bytedance/gopkg/tree/develop/util/gopool [mcache]: https://github.com/bytedance/gopkg/tree/develop/lang/mcache -[io_uring]: https://github.com/axboe/liburing diff --git a/README_CN.md b/README_CN.md index 376691ec..3db6e3ac 100644 --- a/README_CN.md +++ b/README_CN.md @@ -48,12 +48,6 @@ goroutine,大幅增加调度开销。此外,[net.Conn][net.Conn] 没有提 - 支持 TCP,Unix Domain Socket - 支持 Linux,macOS(操作系统) -* **即将开源** - - [io_uring][io_uring] - - Shared Memory IPC - - 支持 TLS - - 支持 UDP - * **不被支持** - Windows(操作系统) @@ -93,4 +87,3 @@ goroutine,大幅增加调度开销。此外,[net.Conn][net.Conn] 没有提 [LinkBuffer]: nocopy_linkbuffer.go [gopool]: https://github.com/bytedance/gopkg/tree/develop/util/gopool [mcache]: https://github.com/bytedance/gopkg/tree/develop/lang/mcache -[io_uring]: https://github.com/axboe/liburing diff --git a/net_dialer.go b/net_dialer.go index c6adfe18..fb10d408 100644 --- a/net_dialer.go +++ b/net_dialer.go @@ -70,7 +70,6 @@ func (d *dialer) DialConnection(network, address string, timeout time.Duration) switch network { case "tcp", "tcp4", "tcp6": return d.dialTCP(ctx, network, address) - // case "udp", "udp4", "udp6": // TODO: unsupported now case "unix", "unixgram", "unixpacket": raddr := &UnixAddr{ UnixAddr: net.UnixAddr{Name: address, Net: network}, diff --git a/net_listener.go b/net_listener.go index 523e6d43..01349b29 100644 --- a/net_listener.go +++ b/net_listener.go @@ -26,9 +26,8 @@ import ( // CreateListener return a new Listener. func CreateListener(network, addr string) (l Listener, err error) { - if network == "udp" { - // TODO: udp listener. - return udpListener(network, addr) + if network == "udp" || network == "udp4" || network == "udp6" { + return nil, Exception(ErrUnsupported, "UDP") } // tcp, tcp4, tcp6, unix ln, err := net.Listen(network, addr) @@ -53,42 +52,17 @@ func ConvertListener(l net.Listener) (nl Listener, err error) { return ln, syscall.SetNonblock(ln.fd, true) } -// TODO: udpListener does not work now. -func udpListener(network, addr string) (l Listener, err error) { - ln := &listener{} - ln.pconn, err = net.ListenPacket(network, addr) - if err != nil { - return nil, err - } - ln.addr = ln.pconn.LocalAddr() - switch pconn := ln.pconn.(type) { - case *net.UDPConn: - ln.file, err = pconn.File() - } - if err != nil { - return nil, err - } - ln.fd = int(ln.file.Fd()) - return ln, syscall.SetNonblock(ln.fd, true) -} - var _ net.Listener = &listener{} type listener struct { - fd int - addr net.Addr // listener's local addr - ln net.Listener // tcp|unix listener - pconn net.PacketConn // udp listener - file *os.File + fd int + addr net.Addr // listener's local addr + ln net.Listener // tcp|unix listener + file *os.File } // Accept implements Listener. func (ln *listener) Accept() (net.Conn, error) { - // udp - if ln.pconn != nil { - return ln.UDPAccept() - } - // tcp fd, sa, err := syscall.Accept(ln.fd) if err != nil { /* https://man7.org/linux/man-pages/man2/accept.2.html @@ -112,11 +86,6 @@ func (ln *listener) Accept() (net.Conn, error) { return nfd, nil } -// TODO: UDPAccept Not implemented. -func (ln *listener) UDPAccept() (net.Conn, error) { - return nil, Exception(ErrUnsupported, "UDP") -} - // Close implements Listener. func (ln *listener) Close() error { if ln.fd != 0 { @@ -128,9 +97,6 @@ func (ln *listener) Close() error { if ln.ln != nil { ln.ln.Close() } - if ln.pconn != nil { - ln.pconn.Close() - } return nil } diff --git a/net_netfd.go b/net_netfd.go index 8b4c028f..0b3b8f0f 100644 --- a/net_netfd.go +++ b/net_netfd.go @@ -33,8 +33,7 @@ type netFD struct { pd *pollDesc // closed marks whether fd has expired closed uint32 - // Whether this is a streaming descriptor, as opposed to a - // packet-based descriptor like a UDP socket. Immutable. + // Whether this is a streaming descriptor. Immutable. isStream bool // Whether a zero byte read indicates EOF. This is false for a // message based socket connection. @@ -42,7 +41,7 @@ type netFD struct { family int // AF_INET, AF_INET6, syscall.AF_UNIX sotype int // syscall.SOCK_STREAM, syscall.SOCK_DGRAM, syscall.SOCK_RAW isConnected bool // handshake completed or use of association with peer - network string // tcp tcp4 tcp6, udp, udp4, udp6, ip, ip4, ip6, unix, unixgram, unixpacket + network string // tcp, tcp4, tcp6, unix, unixgram, unixpacket localAddr net.Addr remoteAddr net.Addr // for detaching conn from poller diff --git a/net_sock.go b/net_sock.go index 8368f047..deca45a6 100644 --- a/net_sock.go +++ b/net_sock.go @@ -17,7 +17,7 @@ import ( "syscall" ) -// A sockaddr represents a TCP, UDP, IP or Unix network endpoint +// A sockaddr represents a TCP, IP or Unix network endpoint // address that can be converted into a syscall.Sockaddr. type sockaddr interface { net.Addr @@ -55,8 +55,8 @@ func internetSocket(ctx context.Context, net string, laddr, raddr sockaddr, soty // address family, both AF_INET and AF_INET6, and a wildcard address // like the following: // -// - A listen for a wildcard communication domain, "tcp" or -// "udp", with a wildcard address: If the platform supports +// - A listen for a wildcard communication domain, "tcp", +// with a wildcard address: If the platform supports // both IPv6 and IPv4-mapped IPv6 communication capabilities, // or does not support IPv4, we use a dual stack, AF_INET6 and // IPV6_V6ONLY=0, wildcard address listen. The dual stack @@ -65,17 +65,17 @@ func internetSocket(ctx context.Context, net string, laddr, raddr sockaddr, soty // Otherwise we prefer an IPv4-only, AF_INET, wildcard address // listen. // -// - A listen for a wildcard communication domain, "tcp" or -// "udp", with an IPv4 wildcard address: same as above. +// - A listen for a wildcard communication domain, "tcp", +// with an IPv4 wildcard address: same as above. // -// - A listen for a wildcard communication domain, "tcp" or -// "udp", with an IPv6 wildcard address: same as above. +// - A listen for a wildcard communication domain, "tcp", +// with an IPv6 wildcard address: same as above. // -// - A listen for an IPv4 communication domain, "tcp4" or "udp4", +// - A listen for an IPv4 communication domain, "tcp4", // with an IPv4 wildcard address: We use an IPv4-only, AF_INET, // wildcard address listen. // -// - A listen for an IPv6 communication domain, "tcp6" or "udp6", +// - A listen for an IPv6 communication domain, "tcp6", // with an IPv6 wildcard address: We use an IPv6-only, AF_INET6 // and IPV6_V6ONLY=1, wildcard address listen. //