mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-17 02:47:51 +01:00
UDT: Fix another bug, this time in udtSocket.Read. This UDT library is a fucking piece of !@#$ code that deserves a special place in hell. It probably takes longer fixing this piece of !@#$ than writing a new library from scratch. booh!
This commit is contained in:
@@ -201,39 +201,28 @@ func (s *udtSocket) Read(p []byte) (n int, err error) {
|
|||||||
err = errors.New("Message truncated") // <- evil buggy
|
err = errors.New("Message truncated") // <- evil buggy
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// for streaming sockets, block until we have at least something to return, then
|
// for streaming sockets, block until we have at least something to return, then fill up the passed buffer as far as we can without blocking again
|
||||||
// fill up the passed buffer as far as we can without blocking again
|
for offset := 0; offset < len(p); {
|
||||||
idx := 0
|
if len(s.currPartialRead) == 0 {
|
||||||
l := len(p)
|
|
||||||
n = 0
|
|
||||||
for idx < l {
|
|
||||||
if s.currPartialRead == nil {
|
|
||||||
// Grab the next data packet
|
// Grab the next data packet
|
||||||
currPartialRead, rerr := s.fetchReadPacket(n == 0 && connErr == nil)
|
if s.currPartialRead, err = s.fetchReadPacket(n == 0 && connErr == nil); err != nil {
|
||||||
s.currPartialRead = currPartialRead
|
return n, err
|
||||||
if rerr != nil {
|
|
||||||
err = rerr
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if s.currPartialRead == nil {
|
if len(s.currPartialRead) == 0 {
|
||||||
if n != 0 {
|
if n != 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if connErr != nil {
|
if connErr != nil {
|
||||||
err = connErr
|
return n, connErr
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
thisN := copy(p[idx:], s.currPartialRead)
|
|
||||||
n = n + thisN
|
thisN := copy(p[offset:], s.currPartialRead)
|
||||||
idx = idx + thisN
|
|
||||||
if n >= len(s.currPartialRead) {
|
n += thisN
|
||||||
// we've exhausted the current data packet, reset to nil
|
offset += thisN
|
||||||
s.currPartialRead = nil
|
s.currPartialRead = s.currPartialRead[thisN:]
|
||||||
} else {
|
|
||||||
s.currPartialRead = s.currPartialRead[n:]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user