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 {
continue
}
stream, err = session.OpenContext(ctx)
stream, err = session.Open()
if err != nil {
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 {
stream, err := session.OpenContext(ctx)
stream, err := session.Open()
if err != nil {
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
}
@ -197,7 +197,7 @@ func (s *h2MuxClientSession) MarkDead(conn *http2.ClientConn) {
s.Close()
}
func (s *h2MuxClientSession) OpenContext(ctx context.Context) (net.Conn, error) {
func (s *h2MuxClientSession) Open() (net.Conn, error) {
pipeInReader, pipeInWriter := io.Pipe()
request := &http.Request{
Method: http.MethodConnect,
@ -212,7 +212,7 @@ func (s *h2MuxClientSession) OpenContext(ctx context.Context) (net.Conn, error)
select {
case <-requestDone:
return
case <-ctx.Done():
case <-time.After(TCPTimeout):
cancel()
}
}()

View file

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