mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
Merge pull request #1030 from lucas-clemente/fix-1029
when the stream write deadline expires, return the data length written
This commit is contained in:
commit
93e99e239c
2 changed files with 27 additions and 5 deletions
|
@ -243,13 +243,10 @@ func (s *stream) Write(p []byte) (int, error) {
|
||||||
s.mutex.Lock()
|
s.mutex.Lock()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
if s.err != nil {
|
if s.err != nil {
|
||||||
return len(p) - len(s.dataForWriting), s.err
|
err = s.err
|
||||||
}
|
}
|
||||||
return len(p), nil
|
return len(p) - len(s.dataForWriting), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stream) GetWriteOffset() protocol.ByteCount {
|
func (s *stream) GetWriteOffset() protocol.ByteCount {
|
||||||
|
|
|
@ -927,6 +927,31 @@ var _ = Describe("Stream", func() {
|
||||||
Expect(time.Now()).To(BeTemporally("~", deadline, scaleDuration(20*time.Millisecond)))
|
Expect(time.Now()).To(BeTemporally("~", deadline, scaleDuration(20*time.Millisecond)))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("returns the number of bytes written, when the deadline expires", func() {
|
||||||
|
mockFC.EXPECT().SendWindowSize().Return(protocol.ByteCount(10000)).AnyTimes()
|
||||||
|
mockFC.EXPECT().AddBytesSent(gomock.Any())
|
||||||
|
deadline := time.Now().Add(scaleDuration(50 * time.Millisecond))
|
||||||
|
str.SetWriteDeadline(deadline)
|
||||||
|
var n int
|
||||||
|
writeReturned := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
defer GinkgoRecover()
|
||||||
|
var err error
|
||||||
|
n, err = strWithTimeout.Write(bytes.Repeat([]byte{0}, 100))
|
||||||
|
Expect(err).To(MatchError(errDeadline))
|
||||||
|
Expect(time.Now()).To(BeTemporally("~", deadline, scaleDuration(20*time.Millisecond)))
|
||||||
|
close(writeReturned)
|
||||||
|
}()
|
||||||
|
var frame *wire.StreamFrame
|
||||||
|
Eventually(func() *wire.StreamFrame {
|
||||||
|
defer GinkgoRecover()
|
||||||
|
frame = str.PopStreamFrame(50)
|
||||||
|
return frame
|
||||||
|
}).ShouldNot(BeNil())
|
||||||
|
Eventually(writeReturned, scaleDuration(80*time.Millisecond)).Should(BeClosed())
|
||||||
|
Expect(n).To(BeEquivalentTo(frame.DataLen()))
|
||||||
|
})
|
||||||
|
|
||||||
It("doesn't unblock if the deadline is changed before the first one expires", func() {
|
It("doesn't unblock if the deadline is changed before the first one expires", func() {
|
||||||
deadline1 := time.Now().Add(scaleDuration(50 * time.Millisecond))
|
deadline1 := time.Now().Add(scaleDuration(50 * time.Millisecond))
|
||||||
deadline2 := time.Now().Add(scaleDuration(100 * time.Millisecond))
|
deadline2 := time.Now().Add(scaleDuration(100 * time.Millisecond))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue