Commit 943b593d authored by Marten Seemann's avatar Marten Seemann
Browse files

remove Serve from the quicConn

parent 1506a05b
......@@ -63,16 +63,6 @@ func (c *quicConn) OpenStream() (smux.Stream, error) {
return &stream{str}, err
}
func (c *quicConn) Serve(handler smux.StreamHandler) {
for { // accept loop
s, err := c.AcceptStream()
if err != nil {
return // err always means closed.
}
go handler(s)
}
}
func (c *quicConn) Close() error {
return c.sess.Close(nil)
}
......
......@@ -6,7 +6,6 @@ import (
"net"
"time"
smux "github.com/libp2p/go-stream-muxer"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/protocol"
......@@ -133,47 +132,4 @@ var _ = Describe("Conn", func() {
Expect(err).To(MatchError(testErr))
})
})
Context("serving", func() {
var (
handler func(smux.Stream)
handlerCalled bool
handlerCalledWith smux.Stream
)
BeforeEach(func() {
handlerCalled = false
handlerCalledWith = nil
handler = func(s smux.Stream) {
handlerCalledWith = s
handlerCalled = true
}
})
It("calls the handler", func() {
str := &mockStream{id: 5}
sess.streamToAccept = str
var returned bool
go func() {
conn.Serve(handler)
returned = true
}()
Eventually(func() bool { return handlerCalled }).Should(BeTrue())
Expect(handlerCalledWith.(*stream).Stream).To(Equal(str))
// make the go-routine return
sess.streamAcceptErr = errors.New("stop test")
})
It("returns when accepting a stream errors", func() {
sess.streamAcceptErr = errors.New("accept err")
var returned bool
go func() {
conn.Serve(handler)
returned = true
}()
Eventually(func() bool { return returned }).Should(BeTrue())
Expect(handlerCalled).To(BeFalse())
})
})
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment