diff --git a/Changelog.md b/Changelog.md index 591752b75..0b357ab8e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ - Add a `quic.Config` option to configure the source address validation - Add a `quic.Config` option to configure the handshake timeout - Add a `quic.Config` option to configure keep-alive +- Implement `net.Conn`-style deadlines for streams - Remove the `tls.Config` from the `quic.Config`. The `tls.Config` must now be passed to the `Dial` and `Listen` functions as a separate parameter. See the [Godoc](https://godoc.org/github.com/lucas-clemente/quic-go) for details. - Changed the log level environment variable to only accept strings ("DEBUG", "INFO", "ERROR"), see [the wiki](https://github.com/lucas-clemente/quic-go/wiki/Logging) for more details. - Rename the `h2quic.QuicRoundTripper` to `h2quic.RoundTripper` diff --git a/h2quic/response_writer_test.go b/h2quic/response_writer_test.go index f8217f316..93ebae162 100644 --- a/h2quic/response_writer_test.go +++ b/h2quic/response_writer_test.go @@ -5,6 +5,7 @@ import ( "io" "net/http" "sync" + "time" "golang.org/x/net/http2" "golang.org/x/net/http2/hpack" @@ -36,6 +37,9 @@ func (s *mockStream) Close() error { s.closed = true; r func (s *mockStream) Reset(error) { s.reset = true } func (s *mockStream) CloseRemote(offset protocol.ByteCount) { s.remoteClosed = true } func (s mockStream) StreamID() protocol.StreamID { return s.id } +func (s *mockStream) SetDeadline(time.Time) error { panic("not implemented") } +func (s *mockStream) SetReadDeadline(time.Time) error { panic("not implemented") } +func (s *mockStream) SetWriteDeadline(time.Time) error { panic("not implemented") } func (s *mockStream) Read(p []byte) (int, error) { n, _ := s.dataToRead.Read(p) diff --git a/interface.go b/interface.go index 4ba4cb42b..685a1ab79 100644 --- a/interface.go +++ b/interface.go @@ -16,6 +16,20 @@ type Stream interface { StreamID() protocol.StreamID // Reset closes the stream with an error. Reset(error) + // SetReadDeadline sets the deadline for future Read calls and + // any currently-blocked Read call. + // A zero value for t means Read will not time out. + SetReadDeadline(t time.Time) error + // SetWriteDeadline sets the deadline for future Write calls + // and any currently-blocked Write call. + // Even if write times out, it may return n > 0, indicating that + // some of the data was successfully written. + // A zero value for t means Write will not time out. + SetWriteDeadline(t time.Time) error + // SetDeadline sets the read and write deadlines associated + // with the connection. It is equivalent to calling both + // SetReadDeadline and SetWriteDeadline. + SetDeadline(t time.Time) error } // A Session is a QUIC connection between two peers. diff --git a/stream.go b/stream.go index 1348eb9cc..f78f815db 100644 --- a/stream.go +++ b/stream.go @@ -304,9 +304,6 @@ func (s *stream) signalWrite() { } } -// SetReadDeadline sets the deadline for future Read calls and -// any currently-blocked Read call. -// A zero value for t means Read will not time out. func (s *stream) SetReadDeadline(t time.Time) error { s.mutex.Lock() oldDeadline := s.readDeadline @@ -319,11 +316,6 @@ func (s *stream) SetReadDeadline(t time.Time) error { return nil } -// SetWriteDeadline sets the deadline for future Write calls -// and any currently-blocked Write call. -// Even if write times out, it may return n > 0, indicating that -// some of the data was successfully written. -// A zero value for t means Write will not time out. func (s *stream) SetWriteDeadline(t time.Time) error { s.mutex.Lock() oldDeadline := s.writeDeadline @@ -335,9 +327,6 @@ func (s *stream) SetWriteDeadline(t time.Time) error { return nil } -// SetDeadline sets the read and write deadlines associated -// with the connection. It is equivalent to calling both -// SetReadDeadline and SetWriteDeadline. func (s *stream) SetDeadline(t time.Time) error { _ = s.SetReadDeadline(t) // SetReadDeadline never errors _ = s.SetWriteDeadline(t) // SetWriteDeadline never errors