Skip to content

Commit

Permalink
allow configuring listen backlog
Browse files Browse the repository at this point in the history
  • Loading branch information
iSchluff committed Nov 17, 2023
1 parent c04da6b commit 26ebc26
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion srt/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 26ebc26

Please sign in to comment.