mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-16 18:37:51 +01:00
UDT: Provide io.EOF signal in udtSocket.fetchReadPacket. Otherwise readers may linger forever.
This commit is contained in:
@@ -2,6 +2,7 @@ package udt
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"sync"
|
||||
"syscall"
|
||||
@@ -141,6 +142,9 @@ func (s *udtSocket) fetchReadPacket(blocking bool) ([]byte, error) {
|
||||
}
|
||||
select {
|
||||
case result = <-s.messageIn:
|
||||
if result == nil { // nil result indicates EOF
|
||||
return nil, io.EOF
|
||||
}
|
||||
return result, nil
|
||||
case _, ok := <-deadline:
|
||||
if !ok {
|
||||
@@ -159,6 +163,9 @@ func (s *udtSocket) fetchReadPacket(blocking bool) ([]byte, error) {
|
||||
// ok we've read some stuff and there's nothing immediately available
|
||||
return nil, nil
|
||||
}
|
||||
if result == nil { // nil result indicates EOF. Using this instead of socket state allows to drain any buffered data first.
|
||||
return nil, io.EOF
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user