[#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
|
return read, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ok bool
|
||||||
|
var ids []*v2refs.ObjectID
|
||||||
|
var i, ln, rem int
|
||||||
|
|
||||||
|
for {
|
||||||
// receive next message
|
// receive next message
|
||||||
ok := x.ctxCall.readResponse()
|
ok = x.ctxCall.readResponse()
|
||||||
if !ok {
|
if !ok {
|
||||||
return read, false
|
return read, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// read new chunk of objects
|
// read new chunk of objects
|
||||||
ids := x.bodyResp.GetIDList()
|
ids = x.bodyResp.GetIDList()
|
||||||
ln := len(ids)
|
|
||||||
|
ln = len(ids)
|
||||||
if ln == 0 {
|
if ln == 0 {
|
||||||
x.ctxCall.err = io.EOF
|
// just skip empty lists since they are not prohibited by protocol
|
||||||
return read, false
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = buf[read:]
|
if rem = len(buf) - read; ln > rem {
|
||||||
if ln > len(buf) {
|
ln = rem
|
||||||
ln = len(buf)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < ln; i++ {
|
for i = 0; i < ln; i++ {
|
||||||
buf[i] = *oid.NewIDFromV2(ids[i]) // need smth better
|
buf[read+i] = *oid.NewIDFromV2(ids[i]) // need smth better
|
||||||
}
|
}
|
||||||
|
|
||||||
read += ln
|
read += ln
|
||||||
|
|
||||||
// save the tail
|
// save the tail and break
|
||||||
x.tail = append(x.tail, ids[ln:]...)
|
x.tail = append(x.tail, ids[ln:]...)
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
return read, true
|
return read, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue