-
Notifications
You must be signed in to change notification settings - Fork 537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] - How to get Listener from server.Default() so that I could use it in different libraries? #545
Comments
I will research it and welcome it together.💕 |
@li-jin-gou Thanks. Please suggest if you've any idea |
Seems that you wanna pass a customized listener to Hertz? |
@welkeyever Yes and also, I want to get a listener from Hertz and use it for different purposes. So basically when Hertz is set up for |
@sujit-baniya It's reasonable to store it in network layer of hertz instance - you may get it through transport-related APIs. But it would be strange that relate listener to |
@welkeyever Yes getting listener from hertz instance would also work. I was giving |
Anything like |
Okay, let me have a try. |
@welkeyever any thought on this issue? |
@sujit-baniya Sorry for the late. I was stumped by other things before. I will continue with this part. |
Possible solution goes here: develop...welkeyever:hertz:feat/more_options_for_transporter Please feel free to add your review comments. The endless example works, however there is a issue related to a third party lib: And we will finally get rid of this lib after this #541. |
@welkeyever Please let me know your thought if we use Options.Listener net.Listener for Engine and pass it to transporter. Something like this: type Options struct {
....
Listener net.Listener
}
func WithListener(ln net.Listener) config.Option {
return config.Option{F: func(o *config.Options) {
o.Listener = ln
}}
} And for each transport we assign this listener to transport // For transporter switch
func NewTransporter(options *config.Options) network.Transporter {
return &transport{
readBufferSize: options.ReadBufferSize,
network: options.Network,
addr: options.Addr,
keepAliveTimeout: options.KeepAliveTimeout,
readTimeout: options.ReadTimeout,
tls: options.TLS,
listenConfig: options.ListenConfig,
ln: options.Listener,
OnAccept: options.OnAccept,
OnConnect: options.OnConnect,
}
} And in if t.ln == nil {
network.UnlinkUdsFile(t.network, t.addr) //nolint:errcheck
t.lock.Lock()
if t.listenConfig != nil {
t.ln, err = t.listenConfig.Listen(context.Background(), t.network, t.addr)
} else {
t.ln, err = net.Listen(t.network, t.addr)
}
t.lock.Unlock()
if err != nil {
return err
}
} |
I did above and got the same error as yours |
Continuously adding options like So I just provider a config-independent way to do so. |
以上为 hertz 的代码, 代码参考:
|
Describe the Question
I'm trying to use
hertz
framework withhttps://github.com/pedia/endless
to allow zero downtime restart. There's an example to include Listener but I'm not sure how to use it withhertz
Reproducible Code
Expected behavior
Able to get listener
Screenshots
If applicable, add screenshots to help explain your question.
Hertz version:
Latest
The text was updated successfully, but these errors were encountered: