feat: add ListenerControl callback to Config#144
Open
krsna1729 wants to merge 2 commits into
Open
Conversation
Go's net.ListenConfig exposes a Control callback so callers can set
arbitrary socket options on the raw fd before bind. gosrt hardcodes
its own ListenControl() inside Listen() but provides no way for the
caller to hook into the same mechanism.
Add a ListenerControl field to Config, following the same signature as
net.ListenConfig.Control. If set, it runs after gosrt's built-in socket
options (SO_REUSEADDR, IP_TOS, IP_TTL) but before the socket is bound.
This lets callers set SO_RCVBUF (or any other socket option) without
gosrt needing to know about application-specific details:
conf.ListenerControl = func(network, address string, c syscall.RawConn) error {
return c.Control(func(fd uintptr) {
syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF, 26214400)
})
}
Verify that the ListenerControl callback is invoked during Listen().
Author
|
cc @ioppermann would be nice to have? I plan to send the counterpart app patch to mediamtx once this is merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Go's
net.ListenConfigexposes aControlcallback so callers can set arbitrary socket options on the raw fd before bind. gosrt hardcodes its ownListenControl()insideListen()but provides no way for the caller to hook into the same mechanism.This PR adds a
ListenerControlfield toConfig, following the same signature asnet.ListenConfig.Control. If set, it runs after gosrt's built-in socket options (SO_REUSEADDR,IP_TOS,IP_TTL) but before the socket is bound.This lets callers like mediamtx set
SO_RCVBUF(or any other socket option) without gosrt needing to know about application-specific details:Changes
config.go: AddListenerControl func(network, address string, c syscall.RawConn) errorfield toConfiglisten.go: Wrap thenet.ListenConfig.Controlcallback to chain gosrt's built-inListenControlwith the caller'sListenerControl(if set)Test plan
go test ./...)ListenerControlis nil (default)