Fixed seek-related bugs in URIReader for HTTP sources
This commit is contained in:
parent
747438746c
commit
b210b4f5af
1 changed files with 22 additions and 18 deletions
|
@ -255,20 +255,30 @@ namespace HTTP{
|
||||||
|
|
||||||
// seek to pos, return true if succeeded.
|
// seek to pos, return true if succeeded.
|
||||||
bool URIReader::seek(const uint64_t pos){
|
bool URIReader::seek(const uint64_t pos){
|
||||||
if (isSeekable()){
|
//Seeking in a non-seekable source? No-op, always fails.
|
||||||
|
if (!isSeekable()){return false;}
|
||||||
|
|
||||||
|
//Reset internal buffers
|
||||||
allData.truncate(0);
|
allData.truncate(0);
|
||||||
bufPos = 0;
|
bufPos = 0;
|
||||||
|
|
||||||
|
//Files always succeed because we use memmap
|
||||||
if (stateType == HTTP::File){
|
if (stateType == HTTP::File){
|
||||||
curPos = pos;
|
curPos = pos;
|
||||||
return true;
|
return true;
|
||||||
}else if (stateType == HTTP::HTTP && supportRangeRequest){
|
|
||||||
INFO_MSG("SEEK: RangeRequest to %" PRIu64, pos);
|
|
||||||
if (!downer.getRangeNonBlocking(myURI.getUrl(), pos, 0)){
|
|
||||||
FAIL_MSG("error loading request");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//HTTP-based needs to do a range request
|
||||||
|
if (stateType == HTTP::HTTP && supportRangeRequest){
|
||||||
|
downer.getSocket().close();
|
||||||
|
downer.getSocket().Received().clear();
|
||||||
|
if (!downer.getRangeNonBlocking(myURI.getUrl(), pos, 0)){
|
||||||
|
FAIL_MSG("Error making range request");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
curPos = pos;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,19 +333,13 @@ namespace HTTP{
|
||||||
|
|
||||||
}else if (stateType == HTTP::HTTP){
|
}else if (stateType == HTTP::HTTP){
|
||||||
downer.continueNonBlocking(cb);
|
downer.continueNonBlocking(cb);
|
||||||
if (curPos == downer.const_data().size()){
|
|
||||||
Util::sleep(50);
|
|
||||||
}
|
|
||||||
curPos = downer.const_data().size();
|
|
||||||
}else{// streaming mode
|
}else{// streaming mode
|
||||||
int s;
|
int s;
|
||||||
static int totaal = 0;
|
|
||||||
if ((downer.getSocket() && downer.getSocket().spool())){// || downer.getSocket().Received().size() > 0){
|
if ((downer.getSocket() && downer.getSocket().spool())){// || downer.getSocket().Received().size() > 0){
|
||||||
s = downer.getSocket().Received().bytes(wantedLen);
|
s = downer.getSocket().Received().bytes(wantedLen);
|
||||||
std::string buf = downer.getSocket().Received().remove(s);
|
std::string buf = downer.getSocket().Received().remove(s);
|
||||||
|
|
||||||
cb.dataCallback(buf.data(), s);
|
cb.dataCallback(buf.data(), s);
|
||||||
totaal += s;
|
|
||||||
}else{
|
}else{
|
||||||
Util::sleep(50);
|
Util::sleep(50);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue