Fix h2mux open

This commit is contained in:
世界 2024-01-24 11:42:45 +08:00
parent 802d9510a7
commit 9bfb33698b
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
3 changed files with 7 additions and 12 deletions

View file

@ -113,7 +113,7 @@ func (c *Client) openStream(ctx context.Context) (net.Conn, error) {
if err != nil { if err != nil {
continue continue
} }
stream, err = session.OpenContext(ctx) stream, err = session.Open()
if err != nil { if err != nil {
continue continue
} }
@ -206,7 +206,7 @@ func (c *Client) offerNew(ctx context.Context) (abstractSession, error) {
} }
func (c *Client) brutalExchange(ctx context.Context, sessionConn net.Conn, session abstractSession) error { func (c *Client) brutalExchange(ctx context.Context, sessionConn net.Conn, session abstractSession) error {
stream, err := session.OpenContext(ctx) stream, err := session.Open()
if err != nil { if err != nil {
return err return err
} }

View file

@ -64,7 +64,7 @@ func (s *h2MuxServerSession) ServeHTTP(writer http.ResponseWriter, request *http
} }
} }
func (s *h2MuxServerSession) OpenContext(ctx context.Context) (net.Conn, error) { func (s *h2MuxServerSession) Open() (net.Conn, error) {
return nil, os.ErrInvalid return nil, os.ErrInvalid
} }
@ -197,7 +197,7 @@ func (s *h2MuxClientSession) MarkDead(conn *http2.ClientConn) {
s.Close() s.Close()
} }
func (s *h2MuxClientSession) OpenContext(ctx context.Context) (net.Conn, error) { func (s *h2MuxClientSession) Open() (net.Conn, error) {
pipeInReader, pipeInWriter := io.Pipe() pipeInReader, pipeInWriter := io.Pipe()
request := &http.Request{ request := &http.Request{
Method: http.MethodConnect, Method: http.MethodConnect,
@ -212,7 +212,7 @@ func (s *h2MuxClientSession) OpenContext(ctx context.Context) (net.Conn, error)
select { select {
case <-requestDone: case <-requestDone:
return return
case <-ctx.Done(): case <-time.After(TCPTimeout):
cancel() cancel()
} }
}() }()

View file

@ -1,7 +1,6 @@
package mux package mux
import ( import (
"context"
"io" "io"
"net" "net"
"reflect" "reflect"
@ -13,7 +12,7 @@ import (
) )
type abstractSession interface { type abstractSession interface {
OpenContext(ctx context.Context) (net.Conn, error) Open() (net.Conn, error)
Accept() (net.Conn, error) Accept() (net.Conn, error)
NumStreams() int NumStreams() int
Close() error Close() error
@ -81,7 +80,7 @@ type smuxSession struct {
*smux.Session *smux.Session
} }
func (s *smuxSession) OpenContext(context.Context) (net.Conn, error) { func (s *smuxSession) Open() (net.Conn, error) {
return s.OpenStream() return s.OpenStream()
} }
@ -97,10 +96,6 @@ type yamuxSession struct {
*yamux.Session *yamux.Session
} }
func (y *yamuxSession) OpenContext(context.Context) (net.Conn, error) {
return y.OpenStream()
}
func (y *yamuxSession) CanTakeNewRequest() bool { func (y *yamuxSession) CanTakeNewRequest() bool {
return true return true
} }