without cancel the context
This commit is contained in:
@@ -11,8 +11,8 @@ import (
|
||||
type conn struct {
|
||||
laddr net.Addr
|
||||
raddr net.Addr
|
||||
closed chan struct{}
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
func (c *conn) Read(b []byte) (n int, err error) {
|
||||
@@ -24,10 +24,8 @@ func (c *conn) Write(b []byte) (n int, err error) {
|
||||
}
|
||||
|
||||
func (c *conn) Close() error {
|
||||
select {
|
||||
case <-c.closed:
|
||||
default:
|
||||
close(c.closed)
|
||||
if c.cancel != nil {
|
||||
c.cancel()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -52,10 +50,6 @@ func (c *conn) SetWriteDeadline(t time.Time) error {
|
||||
return &net.OpError{Op: "set", Net: "http2", Source: nil, Addr: nil, Err: errors.New("deadline not supported")}
|
||||
}
|
||||
|
||||
func (c *conn) Done() <-chan struct{} {
|
||||
return c.closed
|
||||
}
|
||||
|
||||
func (c *conn) Context() context.Context {
|
||||
return c.ctx
|
||||
}
|
||||
|
||||
@@ -172,11 +172,12 @@ func (l *http2Listener) handleFunc(w http.ResponseWriter, r *http.Request) {
|
||||
"w": w,
|
||||
}))
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
conn := &conn{
|
||||
laddr: l.addr,
|
||||
raddr: remoteAddr,
|
||||
closed: make(chan struct{}),
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
}
|
||||
|
||||
select {
|
||||
@@ -186,5 +187,5 @@ func (l *http2Listener) handleFunc(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
<-conn.Done()
|
||||
<-ctx.Done()
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ func (l *mwsListener) upgrade(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := r.Context()
|
||||
if cc, ok := conn.NetConn().(xctx.Context); ok {
|
||||
if cv := cc.Context(); cv != nil {
|
||||
ctx = cv
|
||||
|
||||
@@ -180,7 +180,7 @@ func (l *wsListener) upgrade(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := context.WithoutCancel(r.Context())
|
||||
if cc, ok := conn.NetConn().(xctx.Context); ok {
|
||||
if cv := cc.Context(); cv != nil {
|
||||
ctx = cv
|
||||
|
||||
Reference in New Issue
Block a user