Skip to content

Commit

Permalink
Merge pull request #27 from longzhiri/master
Browse files Browse the repository at this point in the history
fix bug: read 0 bytes from a stream will block forever
  • Loading branch information
xtaci authored Jan 4, 2018
2 parents c3e1824 + d502b06 commit e28719e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ func (s *Stream) ID() uint32 {

// Read implements net.Conn
func (s *Stream) Read(b []byte) (n int, err error) {
if len(b) == 0 {
select {
case <-s.die:
return 0, errors.New(errBrokenPipe)
default:
return 0, nil
}
}

var deadline <-chan time.Time
if d, ok := s.readDeadline.Load().(time.Time); ok && !d.IsZero() {
timer := time.NewTimer(time.Until(d))
Expand Down

0 comments on commit e28719e

Please sign in to comment.