Skip to content

Commit

Permalink
Fix h2mux open
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Jan 24, 2024
1 parent 802d951 commit 9bfb336
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions h2mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
Expand All @@ -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()
}
}()
Expand Down
9 changes: 2 additions & 7 deletions session.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mux

import (
"context"
"io"
"net"
"reflect"
Expand All @@ -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
Expand Down Expand Up @@ -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()
}

Expand All @@ -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
}
Expand Down

0 comments on commit 9bfb336

Please sign in to comment.