mirror of
https://github.com/xtaci/smux.git
synced 2024-04-21 10:51:48 +00:00
Merge pull request #27 from longzhiri/master
fix bug: read 0 bytes from a stream will block forever
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user