Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use embedded structs
Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com>
  • Loading branch information
mohammed90 committed Apr 2, 2025
commit 57a85ede023aa0012cfb1ba069215b9fc104ba11
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ linters:
- whitespace
- zerologlint
settings:
staticcheck:
checks: ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-QF1008"] # default, and exclude 1 more undesired check
errcheck:
exclude-functions:
- fmt.*
Expand Down
16 changes: 8 additions & 8 deletions listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (fcl *fakeCloseListener) Accept() (net.Conn, error) {
err = tconn.SetKeepAlive(false)
}
if err != nil {
Log().With(zap.String("server", fcl.key)).Warn("unable to set keepalive for new connection:", zap.Error(err))
Log().With(zap.String("server", fcl.sharedListener.key)).Warn("unable to set keepalive for new connection:", zap.Error(err))
}
}
return conn, nil
Expand All @@ -165,7 +165,7 @@ func (fcl *fakeCloseListener) Accept() (net.Conn, error) {
// users of this listener, not just our own reference to it; we also don't
// do anything with the error because all we could do is log it, but we
// explicitly assign it to nothing so we don't forget it's there if needed
_ = fcl.clearDeadline()
_ = fcl.sharedListener.clearDeadline()

if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
return nil, fakeClosedErr(fcl)
Expand All @@ -188,8 +188,8 @@ func (fcl *fakeCloseListener) Close() error {
// file). But we can set the deadline in the past,
// and this is kind of cheating, but it works, and
// it apparently even works on Windows.
_ = fcl.setDeadline()
_, _ = listenerPool.Delete(fcl.key)
_ = fcl.sharedListener.setDeadline()
_, _ = listenerPool.Delete(fcl.sharedListener.key)
}
return nil
}
Expand Down Expand Up @@ -236,7 +236,7 @@ func (sl *sharedListener) setDeadline() error {
// Destruct is called by the UsagePool when the listener is
// finally not being used anymore. It closes the socket.
func (sl *sharedListener) Destruct() error {
return sl.Close()
return sl.Listener.Close()
}

// fakeClosePacketConn is like fakeCloseListener, but for PacketConns,
Expand Down Expand Up @@ -279,13 +279,13 @@ func (fcpc *fakeClosePacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err e
func (fcpc *fakeClosePacketConn) Close() error {
if atomic.CompareAndSwapInt32(&fcpc.closed, 0, 1) {
_ = fcpc.SetReadDeadline(time.Now()) // unblock ReadFrom() calls to kick old servers out of their loops
_, _ = listenerPool.Delete(fcpc.key)
_, _ = listenerPool.Delete(fcpc.sharedPacketConn.key)
}
return nil
}

func (fcpc *fakeClosePacketConn) Unwrap() net.PacketConn {
return fcpc.PacketConn
return fcpc.sharedPacketConn.PacketConn
}

// sharedPacketConn is like sharedListener, but for net.PacketConns.
Expand All @@ -296,7 +296,7 @@ type sharedPacketConn struct {

// Destruct closes the underlying socket.
func (spc *sharedPacketConn) Destruct() error {
return spc.Close()
return spc.PacketConn.Close()
}

// Unwrap returns the underlying socket
Expand Down
4 changes: 2 additions & 2 deletions listeners.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ type sharedQuicListener struct {
// Destruct closes the underlying QUIC listener and its associated net.PacketConn.
func (sql *sharedQuicListener) Destruct() error {
// close EarlyListener first to stop any operations being done to the net.PacketConn
_ = sql.Close()
_ = sql.EarlyListener.Close()
// then close the net.PacketConn
return sql.packetConn.Close()
}
Expand Down Expand Up @@ -626,7 +626,7 @@ func (fcql *fakeCloseQuicListener) Accept(_ context.Context) (quic.EarlyConnecti
func (fcql *fakeCloseQuicListener) Close() error {
if atomic.CompareAndSwapInt32(&fcql.closed, 0, 1) {
fcql.contextCancel()
_, _ = listenerPool.Delete(fcql.key)
_, _ = listenerPool.Delete(fcql.sharedQuicListener.key)
}
return nil
}
Expand Down
Loading