Chore: Listener should not expose original net.Listener

This commit is contained in:
gVisor bot 2021-06-13 23:05:22 +08:00
parent 894e2843d5
commit b495157bec
7 changed files with 33 additions and 33 deletions

View file

@ -17,10 +17,10 @@ import (
) )
type Listener struct { type Listener struct {
net.Listener listener net.Listener
address string address string
closed bool closed bool
cache *cache.Cache cache *cache.Cache
} }
func New(addr string, in chan<- C.ConnContext) (*Listener, error) { func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
@ -31,7 +31,7 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
hl := &Listener{l, addr, false, cache.New(30 * time.Second)} hl := &Listener{l, addr, false, cache.New(30 * time.Second)}
go func() { go func() {
for { for {
c, err := hl.Accept() c, err := hl.listener.Accept()
if err != nil { if err != nil {
if hl.closed { if hl.closed {
break break
@ -47,7 +47,7 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
func (l *Listener) Close() { func (l *Listener) Close() {
l.closed = true l.closed = true
l.Listener.Close() l.listener.Close()
} }
func (l *Listener) Address() string { func (l *Listener) Address() string {

View file

@ -12,10 +12,10 @@ import (
) )
type Listener struct { type Listener struct {
net.Listener listener net.Listener
address string address string
closed bool closed bool
cache *cache.Cache cache *cache.Cache
} }
func New(addr string, in chan<- C.ConnContext) (*Listener, error) { func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
@ -27,7 +27,7 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
ml := &Listener{l, addr, false, cache.New(30 * time.Second)} ml := &Listener{l, addr, false, cache.New(30 * time.Second)}
go func() { go func() {
for { for {
c, err := ml.Accept() c, err := ml.listener.Accept()
if err != nil { if err != nil {
if ml.closed { if ml.closed {
break break
@ -43,7 +43,7 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
func (l *Listener) Close() { func (l *Listener) Close() {
l.closed = true l.closed = true
l.Listener.Close() l.listener.Close()
} }
func (l *Listener) Address() string { func (l *Listener) Address() string {

View file

@ -8,9 +8,9 @@ import (
) )
type Listener struct { type Listener struct {
net.Listener listener net.Listener
address string address string
closed bool closed bool
} }
func New(addr string, in chan<- C.ConnContext) (*Listener, error) { func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
@ -38,7 +38,7 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
func (l *Listener) Close() { func (l *Listener) Close() {
l.closed = true l.closed = true
l.Listener.Close() l.listener.Close()
} }
func (l *Listener) Address() string { func (l *Listener) Address() string {

View file

@ -12,9 +12,9 @@ import (
) )
type Listener struct { type Listener struct {
net.Listener listener net.Listener
address string address string
closed bool closed bool
} }
func New(addr string, in chan<- C.ConnContext) (*Listener, error) { func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
@ -42,7 +42,7 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
func (l *Listener) Close() { func (l *Listener) Close() {
l.closed = true l.closed = true
l.Listener.Close() l.listener.Close()
} }
func (l *Listener) Address() string { func (l *Listener) Address() string {

View file

@ -12,9 +12,9 @@ import (
) )
type UDPListener struct { type UDPListener struct {
net.PacketConn packetConn net.PacketConn
address string address string
closed bool closed bool
} }
func NewUDP(addr string, in chan<- *inbound.PacketAdapter) (*UDPListener, error) { func NewUDP(addr string, in chan<- *inbound.PacketAdapter) (*UDPListener, error) {
@ -48,7 +48,7 @@ func NewUDP(addr string, in chan<- *inbound.PacketAdapter) (*UDPListener, error)
func (l *UDPListener) Close() error { func (l *UDPListener) Close() error {
l.closed = true l.closed = true
return l.PacketConn.Close() return l.packetConn.Close()
} }
func (l *UDPListener) Address() string { func (l *UDPListener) Address() string {

View file

@ -9,9 +9,9 @@ import (
) )
type Listener struct { type Listener struct {
net.Listener listener net.Listener
address string address string
closed bool closed bool
} }
func New(addr string, in chan<- C.ConnContext) (*Listener, error) { func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
@ -32,7 +32,7 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
} }
rl := &Listener{ rl := &Listener{
Listener: l, listener: l,
address: addr, address: addr,
} }
@ -54,7 +54,7 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
func (l *Listener) Close() { func (l *Listener) Close() {
l.closed = true l.closed = true
l.Listener.Close() l.listener.Close()
} }
func (l *Listener) Address() string { func (l *Listener) Address() string {

View file

@ -10,9 +10,9 @@ import (
) )
type UDPListener struct { type UDPListener struct {
net.PacketConn packetConn net.PacketConn
address string address string
closed bool closed bool
} }
func NewUDP(addr string, in chan<- *inbound.PacketAdapter) (*UDPListener, error) { func NewUDP(addr string, in chan<- *inbound.PacketAdapter) (*UDPListener, error) {
@ -61,7 +61,7 @@ func NewUDP(addr string, in chan<- *inbound.PacketAdapter) (*UDPListener, error)
func (l *UDPListener) Close() error { func (l *UDPListener) Close() error {
l.closed = true l.closed = true
return l.PacketConn.Close() return l.packetConn.Close()
} }
func (l *UDPListener) Address() string { func (l *UDPListener) Address() string {