Browse Source

change OpenStream to accept a context

pull/1424/head
Marten Seemann 4 years ago
parent
commit
ee958afaf3
  1. 2
      p2p/transport/quic/cmd/client/main.go
  2. 4
      p2p/transport/quic/conn.go
  3. 6
      p2p/transport/quic/conn_test.go

2
p2p/transport/quic/cmd/client/main.go

@ -49,7 +49,7 @@ func run(raddr string, p string) error {
return err
}
defer conn.Close()
str, err := conn.OpenStream()
str, err := conn.OpenStream(context.Background())
if err != nil {
return err
}

4
p2p/transport/quic/conn.go

@ -37,8 +37,8 @@ func (c *conn) IsClosed() bool {
}
// OpenStream creates a new stream.
func (c *conn) OpenStream() (mux.MuxedStream, error) {
qstr, err := c.sess.OpenStreamSync(context.Background())
func (c *conn) OpenStream(ctx context.Context) (mux.MuxedStream, error) {
qstr, err := c.sess.OpenStreamSync(ctx)
return &stream{Stream: qstr}, err
}

6
p2p/transport/quic/conn_test.go

@ -130,7 +130,7 @@ var _ = Describe("Connection", func() {
Expect(err).ToNot(HaveOccurred())
defer serverConn.Close()
str, err := conn.OpenStream()
str, err := conn.OpenStream(context.Background())
Expect(err).ToNot(HaveOccurred())
_, err = str.Write([]byte("foobar"))
Expect(err).ToNot(HaveOccurred())
@ -251,7 +251,7 @@ var _ = Describe("Connection", func() {
for _, c := range []tpt.CapableConn{serverConn1, serverConn2} {
go func(conn tpt.CapableConn) {
defer GinkgoRecover()
str, err := conn.OpenStream()
str, err := conn.OpenStream(context.Background())
Expect(err).ToNot(HaveOccurred())
defer str.Close()
_, err = str.Write(data)
@ -315,7 +315,7 @@ var _ = Describe("Connection", func() {
defer GinkgoRecover()
conn, err := ln.Accept()
Expect(err).ToNot(HaveOccurred())
str, err := conn.OpenStream()
str, err := conn.OpenStream(context.Background())
Expect(err).ToNot(HaveOccurred())
str.Write([]byte("foobar"))
}()

Loading…
Cancel
Save