Commit f8693927 authored by Marten Seemann's avatar Marten Seemann
Browse files

implement the new stream reset recently added to smux.Stream

It was added in
https://github.com/libp2p/go-stream-muxer/commit/be2992bb9
parent 617087ce
...@@ -52,13 +52,15 @@ func newQuicConn(sess quic.Session, t tpt.Transport) (*quicConn, error) { ...@@ -52,13 +52,15 @@ func newQuicConn(sess quic.Session, t tpt.Transport) (*quicConn, error) {
} }
func (c *quicConn) AcceptStream() (smux.Stream, error) { func (c *quicConn) AcceptStream() (smux.Stream, error) {
return c.sess.AcceptStream() str, err := c.sess.AcceptStream()
return &stream{str}, err
} }
// OpenStream opens a new stream // OpenStream opens a new stream
// It blocks until a new stream can be opened (when limited by the QUIC maximum stream limit) // It blocks until a new stream can be opened (when limited by the QUIC maximum stream limit)
func (c *quicConn) OpenStream() (smux.Stream, error) { func (c *quicConn) OpenStream() (smux.Stream, error) {
return c.sess.OpenStreamSync() str, err := c.sess.OpenStreamSync()
return &stream{str}, err
} }
func (c *quicConn) Serve(handler smux.StreamHandler) { func (c *quicConn) Serve(handler smux.StreamHandler) {
......
...@@ -101,7 +101,7 @@ var _ = Describe("Conn", func() { ...@@ -101,7 +101,7 @@ var _ = Describe("Conn", func() {
sess.streamToOpen = s sess.streamToOpen = s
str, err := conn.OpenStream() str, err := conn.OpenStream()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(str).To(Equal(s)) Expect(str.(*stream).Stream).To(Equal(s))
}) })
It("errors when it can't open a stream", func() { It("errors when it can't open a stream", func() {
...@@ -118,7 +118,7 @@ var _ = Describe("Conn", func() { ...@@ -118,7 +118,7 @@ var _ = Describe("Conn", func() {
sess.streamToAccept = s sess.streamToAccept = s
str, err := conn.AcceptStream() str, err := conn.AcceptStream()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(str).To(Equal(s)) Expect(str.(*stream).Stream).To(Equal(s))
}) })
It("errors when it can't open a stream", func() { It("errors when it can't open a stream", func() {
...@@ -154,7 +154,7 @@ var _ = Describe("Conn", func() { ...@@ -154,7 +154,7 @@ var _ = Describe("Conn", func() {
returned = true returned = true
}() }()
Eventually(func() bool { return handlerCalled }).Should(BeTrue()) Eventually(func() bool { return handlerCalled }).Should(BeTrue())
Expect(handlerCalledWith).To(Equal(str)) Expect(handlerCalledWith.(*stream).Stream).To(Equal(str))
// make the go-routine return // make the go-routine return
sess.streamAcceptErr = errors.New("stop test") sess.streamAcceptErr = errors.New("stop test")
}) })
......
package libp2pquic
import (
smux "github.com/libp2p/go-stream-muxer"
"github.com/lucas-clemente/quic-go"
)
type stream struct {
quic.Stream
}
var _ smux.Stream = &stream{}
func (s *stream) Reset() error {
s.Stream.Reset(nil)
return nil
}
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