1
0
Fork 0

Add support for UDP routing in systemd socket activation

This commit is contained in:
tsiid 2025-01-21 11:38:09 +03:00 committed by GitHub
parent 95dd17e020
commit 261e4395f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 158 additions and 54 deletions

View file

@ -0,0 +1,41 @@
package server
import (
"errors"
"net"
)
type SocketActivation struct {
enabled bool
listeners map[string]net.Listener
conns map[string]net.PacketConn
}
func (s *SocketActivation) isEnabled() bool {
return s.enabled
}
func (s *SocketActivation) getListener(name string) (net.Listener, error) {
listener, ok := s.listeners[name]
if !ok {
return nil, errors.New("unable to find socket activation TCP listener for entryPoint")
}
return listener, nil
}
func (s *SocketActivation) getConn(name string) (net.PacketConn, error) {
conn, ok := s.conns[name]
if !ok {
return nil, errors.New("unable to find socket activation UDP listener for entryPoint")
}
return conn, nil
}
var socketActivation *SocketActivation
func init() {
// Populates pre-defined TCP and UDP listeners provided by systemd socket activation.
socketActivation = populateSocketActivationListeners()
}