Skip to content

Commit

Permalink
remove MultistreamMuxer.NegotiateLazy (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann authored Nov 16, 2022
1 parent 225d479 commit c11bb0e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
10 changes: 0 additions & 10 deletions multistream.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,6 @@ func (msm *MultistreamMuxer) findHandler(proto string) *Handler {
return nil
}

// NegotiateLazy performs protocol selection and returns
// a multistream, the protocol used, the handler and an error. It is lazy
// because the write-handshake is performed on a subroutine, allowing this
// to return before that handshake is completed.
// Deprecated: use Negotiate instead.
func (msm *MultistreamMuxer) NegotiateLazy(rwc io.ReadWriteCloser) (rwc_ io.ReadWriteCloser, proto string, handler HandlerFunc, err error) {
proto, handler, err = msm.Negotiate(rwc)
return rwc, proto, handler, err
}

// Negotiate performs protocol selection and returns the protocol name and
// the matching handler function for it (or an error).
func (msm *MultistreamMuxer) Negotiate(rwc io.ReadWriteCloser) (proto string, handler HandlerFunc, err error) {
Expand Down
16 changes: 6 additions & 10 deletions multistream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,15 @@ func TestProtocolNegotiationLazy(t *testing.T) {
mux.AddHandler("/b", nil)
mux.AddHandler("/c", nil)

var ac io.ReadWriteCloser
done := make(chan struct{})
go func() {
m, selected, _, err := mux.NegotiateLazy(a)
selected, _, err := mux.Negotiate(a)
if err != nil {
t.Error(err)
}
if selected != "/a" {
t.Error("incorrect protocol selected")
}
ac = m
close(done)
}()

Expand All @@ -146,7 +144,7 @@ func TestProtocolNegotiationLazy(t *testing.T) {
case <-done:
}

verifyPipe(t, ac, b)
verifyPipe(t, a, b)
}

func TestProtocolNegotiationUnsupported(t *testing.T) {
Expand Down Expand Up @@ -183,7 +181,7 @@ func TestNegLazyStressRead(t *testing.T) {
go func() {
defer close(done)
for rwc := range listener {
m, selected, _, err := mux.NegotiateLazy(rwc)
selected, _, err := mux.Negotiate(rwc)
if err != nil {
t.Error(err)
return
Expand All @@ -195,8 +193,7 @@ func TestNegLazyStressRead(t *testing.T) {
}

buf := make([]byte, len(message))
_, err = io.ReadFull(m, buf)
if err != nil {
if _, err := io.ReadFull(rwc, buf); err != nil {
t.Error(err)
return
}
Expand Down Expand Up @@ -237,7 +234,7 @@ func TestNegLazyStressWrite(t *testing.T) {
listener := make(chan io.ReadWriteCloser)
go func() {
for rwc := range listener {
m, selected, _, err := mux.NegotiateLazy(rwc)
selected, _, err := mux.Negotiate(rwc)
if err != nil {
t.Error(err)
return
Expand All @@ -248,8 +245,7 @@ func TestNegLazyStressWrite(t *testing.T) {
return
}

_, err = m.Write(message)
if err != nil {
if _, err := rwc.Write(message); err != nil {
t.Error(err)
return
}
Expand Down

0 comments on commit c11bb0e

Please sign in to comment.