-
Notifications
You must be signed in to change notification settings - Fork 158
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
context.Context based cancellation #189
Comments
It's also related to #163 (comment). The new API could be: func Dial(ctx context.Context, network string, raddr *net.UDPAddr, config *Config) (*Conn, error) {}
func Client(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {}
func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {} In this API, we might be able to drop |
Adding |
I'd vote for the second option, adding the |
On |
|
I opened a draft PR at #191. One problem is that |
To be discussedConnectTimeout config 06468a3Having timeout both by Error value on timeout dbf9263Currently, |
Adding a // function to make a context used in Dial(), Client(), Server(), and Accept().
// If it is nil, default context with 30s timeout is used.
ConnectContextMaker func() (context.Context, func()) to ctxParent, cancelParent := context.WithCancel(context.Background())
defer cancelParent()
config := &dtls.Config{
ConnectContextMaker: func() (context.Context, func()) {
return context.WithTimeout(ctxParent, 30*time.Second)
},
}
listener, err := dtls.Listen("udp", addr, config)
conn, err := listener.Accept() func (l *listener) Accept() (net.Conn, error) {
c, err := l.parent.Accept()
if err != nil {
return nil, err
}
ctx, cancel := l.config.ConnectContextMaker()
defer cancel()
return ServerWithContext(ctx, c, l.config)
} allows to Inherit the parent context to (06468a3 implements this) |
Proposed at #147.
#147 (comment)
The text was updated successfully, but these errors were encountered: