forked from TrueCloudLab/frostfs-sdk-go
[#149] client: Do not finish on empty ID list in ObjectListReader
In previous implementation `ObjectListReader.Read` returned `false` on server responded with empty ID list. This could cause premature end of reading since the protocol does not forbid intermediate empty lists. Do not stop if ID list from response body is empty. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
32af7251f2
commit
8e99e8a818
1 changed files with 34 additions and 26 deletions
|
@ -136,34 +136,42 @@ func (x *ObjectListReader) Read(buf []oid.ID) (int, bool) {
|
|||
return read, true
|
||||
}
|
||||
|
||||
// receive next message
|
||||
ok := x.ctxCall.readResponse()
|
||||
if !ok {
|
||||
return read, false
|
||||
var ok bool
|
||||
var ids []*v2refs.ObjectID
|
||||
var i, ln, rem int
|
||||
|
||||
for {
|
||||
// receive next message
|
||||
ok = x.ctxCall.readResponse()
|
||||
if !ok {
|
||||
return read, false
|
||||
}
|
||||
|
||||
// read new chunk of objects
|
||||
ids = x.bodyResp.GetIDList()
|
||||
|
||||
ln = len(ids)
|
||||
if ln == 0 {
|
||||
// just skip empty lists since they are not prohibited by protocol
|
||||
continue
|
||||
}
|
||||
|
||||
if rem = len(buf) - read; ln > rem {
|
||||
ln = rem
|
||||
}
|
||||
|
||||
for i = 0; i < ln; i++ {
|
||||
buf[read+i] = *oid.NewIDFromV2(ids[i]) // need smth better
|
||||
}
|
||||
|
||||
read += ln
|
||||
|
||||
// save the tail and break
|
||||
x.tail = append(x.tail, ids[ln:]...)
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
// read new chunk of objects
|
||||
ids := x.bodyResp.GetIDList()
|
||||
ln := len(ids)
|
||||
if ln == 0 {
|
||||
x.ctxCall.err = io.EOF
|
||||
return read, false
|
||||
}
|
||||
|
||||
buf = buf[read:]
|
||||
if ln > len(buf) {
|
||||
ln = len(buf)
|
||||
}
|
||||
|
||||
for i := 0; i < ln; i++ {
|
||||
buf[i] = *oid.NewIDFromV2(ids[i]) // need smth better
|
||||
}
|
||||
|
||||
read += ln
|
||||
|
||||
// save the tail
|
||||
x.tail = append(x.tail, ids[ln:]...)
|
||||
|
||||
return read, true
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue