-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathudp.go
36 lines (31 loc) · 763 Bytes
/
udp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package caddy_socket_activation
import (
"context"
"errors"
"net"
)
func init() {
//caddyhttp.RegisterNetworkHTTP3("socket-activation", "socket-activation-udp")
//caddy.RegisterNetwork("socket-activation-udp", listenUDP)
}
// not used for now
func listenUDP(ctx context.Context, network, addr string, cfg net.ListenConfig) (any, error) {
files := Files(true)
if len(files) == 0 {
return nil, errors.New("no file descriptors passed")
}
host, _, err := net.SplitHostPort(addr)
if err != nil {
host = addr
}
for _, file := range files {
if pc, err := net.FilePacketConn(file); err == nil {
if file.Name() == host {
return pc, nil
} else {
_ = pc.Close()
}
}
}
return nil, errors.New("no matching file descriptor found")
}