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:
Kleissner
2021-11-04 17:05:53 +01:00
parent e141510b9c
commit e6846c232c

View File

@@ -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