Skip to content

Commit

Permalink
Merge pull request xbmc#2675 from ulion/curl_range_rework
Browse files Browse the repository at this point in the history
Fixed: do not send Range request header when encounter error.
  • Loading branch information
ulion committed May 17, 2013
2 parents 78ea7ff + 198cf20 commit f6a7fb2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 19 additions & 1 deletion xbmc/filesystem/CurlFile.cpp
Expand Up @@ -246,6 +246,7 @@ CCurlFile::CReadState::CReadState()
m_bufferSize = 0;
m_cancelled = false;
m_bFirstLoop = true;
m_sendRange = true;
m_headerdone = false;
m_readBuffer = 0;
m_isPaused = false;
Expand Down Expand Up @@ -308,8 +309,13 @@ void CCurlFile::CReadState::SetResume(void)
* request header. If we don't the server may provide different content causing seeking to fail.
* This only affects HTTP-like items, for FTP it's a null operation.
*/
if (m_filePos == 0)
if (m_sendRange && m_filePos == 0)
g_curlInterface.easy_setopt(m_easyHandle, CURLOPT_RANGE, "0-");
else
{
g_curlInterface.easy_setopt(m_easyHandle, CURLOPT_RANGE, NULL);
m_sendRange = false;
}

g_curlInterface.easy_setopt(m_easyHandle, CURLOPT_RESUME_FROM_LARGE, m_filePos);
}
Expand Down Expand Up @@ -902,6 +908,7 @@ bool CCurlFile::Open(const CURL& url)
// setup common curl options
SetCommonOptions(m_state);
SetRequestHeaders(m_state);
m_state->m_sendRange = m_seekable;

m_httpresponse = m_state->Connect(m_bufferSize);
if( m_httpresponse < 0 || m_httpresponse >= 400)
Expand Down Expand Up @@ -1179,6 +1186,7 @@ int64_t CCurlFile::Seek(int64_t iFilePosition, int iWhence)
SetRequestHeaders(m_state);

m_state->m_filePos = nextPos;
m_state->m_sendRange = true;

long response = m_state->Connect(m_bufferSize);
if(response < 0 && (m_state->m_fileSize == 0 || m_state->m_fileSize != m_state->m_filePos))
Expand Down Expand Up @@ -1425,6 +1433,16 @@ bool CCurlFile::CReadState::FillBuffer(unsigned int want)
msg->data.result == CURLE_RECV_ERROR) &&
!m_bFirstLoop)
CURLresult = msg->data.result;
else if ( (msg->data.result == CURLE_HTTP_RANGE_ERROR ||
msg->data.result == CURLE_HTTP_RETURNED_ERROR) &&
m_bFirstLoop &&
m_filePos == 0 &&
m_sendRange)
{
// If server returns a range or http error, retry with range disabled
CURLresult = msg->data.result;
m_sendRange = false;
}
else
return false;
}
Expand Down
1 change: 1 addition & 0 deletions xbmc/filesystem/CurlFile.h
Expand Up @@ -114,6 +114,7 @@ namespace XFILE
int64_t m_filePos;
bool m_bFirstLoop;
bool m_isPaused;
bool m_sendRange;

char* m_readBuffer;

Expand Down

0 comments on commit f6a7fb2

Please sign in to comment.