aboutsummaryrefslogtreecommitdiffhomepage
path: root/listen.go
diff options
context:
space:
mode:
authorMatt Holt <[email protected]>2022-09-28 13:35:51 -0600
committerGitHub <[email protected]>2022-09-28 13:35:51 -0600
commite3e8aabbcf65d37516bb97f9dc0f77df52f8cf55 (patch)
treea7f50b045ab2b526d0f1dc83f9a8adbd502f5d14 /listen.go
parentd0556929a4a574ea67be4c1ca2a2741b0f7a52c2 (diff)
downloadcaddy-e3e8aabbcf65d37516bb97f9dc0f77df52f8cf55.tar.gz
caddy-e3e8aabbcf65d37516bb97f9dc0f77df52f8cf55.zip
core: Refactor and improve listener logic (#5089)
* core: Refactor, improve listener logic Deprecate: - caddy.Listen - caddy.ListenTimeout - caddy.ListenPacket Prefer caddy.NetworkAddress.Listen() instead. Change: - caddy.ListenQUIC (hopefully to remove later) - caddy.ListenerFunc signature (add context and ListenConfig) - Don't emit Alt-Svc header advertising h3 over HTTP/3 - Use quic.ListenEarly instead of quic.ListenEarlyAddr; this gives us more flexibility (e.g. possibility of HTTP/3 over UDS) but also introduces a new issue: https://github.com/lucas-clemente/quic-go/issues/3560#issuecomment-1258959608 - Unlink unix socket before and after use * Appease the linter * Keep ListenAll
Diffstat (limited to 'listen.go')
-rw-r--r--listen.go26
1 files changed, 7 insertions, 19 deletions
diff --git a/listen.go b/listen.go
index 268785a3d..1ca168744 100644
--- a/listen.go
+++ b/listen.go
@@ -20,7 +20,7 @@
package caddy
import (
- "fmt"
+ "context"
"net"
"sync"
"sync/atomic"
@@ -29,21 +29,14 @@ import (
"go.uber.org/zap"
)
-func ListenTimeout(network, addr string, keepAlivePeriod time.Duration) (net.Listener, error) {
- // check to see if plugin provides listener
- if ln, err := getListenerFromPlugin(network, addr); err != nil || ln != nil {
- return ln, err
- }
-
- lnKey := listenerKey(network, addr)
+func reuseUnixSocket(network, addr string) (any, error) {
+ return nil, nil
+}
+func listenTCPOrUnix(ctx context.Context, lnKey string, network, address string, config net.ListenConfig) (net.Listener, error) {
sharedLn, _, err := listenerPool.LoadOrNew(lnKey, func() (Destructor, error) {
- ln, err := net.Listen(network, addr)
+ ln, err := config.Listen(ctx, network, address)
if err != nil {
- // https://github.com/caddyserver/caddy/pull/4534
- if isUnixNetwork(network) && isListenBindAddressAlreadyInUseError(err) {
- return nil, fmt.Errorf("%w: this can happen if Caddy was forcefully killed", err)
- }
return nil, err
}
return &sharedListener{Listener: ln, key: lnKey}, nil
@@ -51,8 +44,7 @@ func ListenTimeout(network, addr string, keepAlivePeriod time.Duration) (net.Lis
if err != nil {
return nil, err
}
-
- return &fakeCloseListener{sharedListener: sharedLn.(*sharedListener), keepAlivePeriod: keepAlivePeriod}, nil
+ return &fakeCloseListener{sharedListener: sharedLn.(*sharedListener), keepAlivePeriod: config.KeepAlive}, nil
}
// fakeCloseListener is a private wrapper over a listener that
@@ -156,8 +148,6 @@ func (sl *sharedListener) clearDeadline() error {
switch ln := sl.Listener.(type) {
case *net.TCPListener:
err = ln.SetDeadline(time.Time{})
- case *net.UnixListener:
- err = ln.SetDeadline(time.Time{})
}
sl.deadline = false
}
@@ -173,8 +163,6 @@ func (sl *sharedListener) setDeadline() error {
switch ln := sl.Listener.(type) {
case *net.TCPListener:
err = ln.SetDeadline(timeInPast)
- case *net.UnixListener:
- err = ln.SetDeadline(timeInPast)
}
sl.deadline = true
}