diff --git a/interface.go b/interface.go index 685a1ab79..c4b7ed30f 100644 --- a/interface.go +++ b/interface.go @@ -10,7 +10,13 @@ import ( // Stream is the interface implemented by QUIC streams type Stream interface { + // Read reads data from the stream. + // Read can be made to time out and return a net.Error with Timeout() == true + // after a fixed time limit; see SetDeadline and SetReadDeadline. io.Reader + // Write writes data to the stream. + // Write can be made to time out and return a net.Error with Timeout() == true + // after a fixed time limit; see SetDeadline and SetWriteDeadline. io.Writer io.Closer StreamID() protocol.StreamID diff --git a/stream.go b/stream.go index f78f815db..6a3d4a06f 100644 --- a/stream.go +++ b/stream.go @@ -1,9 +1,9 @@ package quic import ( - "errors" "fmt" "io" + "net" "sync" "time" @@ -55,7 +55,13 @@ type stream struct { flowControlManager flowcontrol.FlowControlManager } -var errDeadline = errors.New("deadline exceeded") +type deadlineError struct{} + +func (deadlineError) Error() string { return "deadline exceeded" } +func (deadlineError) Temporary() bool { return true } +func (deadlineError) Timeout() bool { return true } + +var errDeadline net.Error = &deadlineError{} // newStream creates a new Stream func newStream(StreamID protocol.StreamID, diff --git a/stream_test.go b/stream_test.go index 0d1bd6e10..e57dce2fd 100644 --- a/stream_test.go +++ b/stream_test.go @@ -255,6 +255,11 @@ var _ = Describe("Stream", func() { }) Context("deadlines", func() { + It("the deadline error has the right net.Error properties", func() { + Expect(errDeadline.Temporary()).To(BeTrue()) + Expect(errDeadline.Timeout()).To(BeTrue()) + }) + It("returns an error when Read is called after the deadline", func() { mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(6)).AnyTimes() f := &frames.StreamFrame{Data: []byte("foobar")}