From 26ebc2664d341d7a89594fa235fbd85d26391434 Mon Sep 17 00:00:00 2001 From: Anton Schubert Date: Fri, 17 Nov 2023 16:23:19 +0100 Subject: [PATCH] allow configuring listen backlog --- config.toml.example | 3 +++ config/config.go | 4 ++++ config/config_test.go | 1 + main.go | 1 + srt/server.go | 3 ++- 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/config.toml.example b/config.toml.example index 6fda6e3..c265194 100644 --- a/config.toml.example +++ b/config.toml.example @@ -41,6 +41,9 @@ addresses = ["localhost:1337"] # Set packet size in Bytes for SRT socket, 1316 Bytes is generally used for MPEG-TS the maximum is 1456 Bytes #packetSize = 1316 +# Max number of pending clients in the accept queue +#listenBacklog = 10 + [api] # Set to false to disable the API endpoint #enabled = true diff --git a/config/config.go b/config/config.go index b48f968..90c21ff 100644 --- a/config/config.go +++ b/config/config.go @@ -36,6 +36,9 @@ type AppConfig struct { // max size of packets in bytes, default is 1316 PacketSize uint + + // max number of pending connections, default is 10 + ListenBacklog int } type AuthConfig struct { @@ -90,6 +93,7 @@ func Parse(paths []string) (*Config, error) { Buffersize: 384000, // 1s @ 3Mbits/s SyncClients: false, PacketSize: 1316, // max is 1456 + ListenBacklog: 10, }, Auth: AuthConfig{ Type: "static", diff --git a/config/config_test.go b/config/config_test.go index 789bc6c..85ed96a 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -21,6 +21,7 @@ func TestConfig(t *testing.T) { assert.Equal(t, conf.App.LossMaxTTL, uint(50)) assert.Equal(t, conf.App.ListenTimeout, uint(5555)) assert.Equal(t, conf.App.PublicAddress, "dontlookmeup:5432") + assert.Equal(t, conf.App.ListenBacklog, 30) assert.Equal(t, conf.API.Enabled, false) assert.Equal(t, conf.API.Address, ":1234") diff --git a/main.go b/main.go index 2e0910f..4a8c012 100644 --- a/main.go +++ b/main.go @@ -67,6 +67,7 @@ func main() { LossMaxTTL: conf.App.LossMaxTTL, SyncClients: conf.App.SyncClients, Auth: auth, + ListenBacklog: conf.App.ListenBacklog, }, Relay: relay.RelayConfig{ BufferSize: conf.App.Buffersize, diff --git a/srt/server.go b/srt/server.go index c69933e..db50f30 100644 --- a/srt/server.go +++ b/srt/server.go @@ -36,6 +36,7 @@ type ServerConfig struct { LossMaxTTL uint Auth auth.Authenticator SyncClients bool + ListenBacklog int } // Server is an interface for a srt relay server @@ -143,7 +144,7 @@ func (s *ServerImpl) listenAt(ctx context.Context, host string, port uint16) err log.Printf("Error settings lossmaxttl: %s", err) } sck.SetListenCallback(s.listenCallback) - err := sck.Listen(5) + err := sck.Listen(s.config.ListenBacklog) if err != nil { return fmt.Errorf("Listen failed for %v:%v : %v", host, port, err) }