Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
7 changes: 0 additions & 7 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(操作系统)

Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion net_dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
46 changes: 6 additions & 40 deletions net_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
}

Expand Down
5 changes: 2 additions & 3 deletions net_netfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@ 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.
zeroReadIsEOF bool
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
Expand Down
18 changes: 9 additions & 9 deletions net_sock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
//
Expand Down
Loading