Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
0dd5ebbd
Commit
0dd5ebbd
authored
Mar 15, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
input/curl: move _seek() into the CurlInputStream class
parent
2ae60767
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
38 deletions
+44
-38
CurlInputPlugin.cxx
src/input/plugins/CurlInputPlugin.cxx
+44
-38
No files found.
src/input/plugins/CurlInputPlugin.cxx
View file @
0dd5ebbd
...
...
@@ -184,6 +184,8 @@ struct CurlInputStream {
return
easy
==
nullptr
&&
buffers
.
empty
();
}
bool
Seek
(
InputPlugin
::
offset_type
offset
,
int
whence
,
Error
&
error
);
Tag
*
ReadTag
();
bool
IsAvailable
()
const
{
...
...
@@ -1063,21 +1065,17 @@ CurlInputStream::InitEasy(Error &error)
return
true
;
}
static
bool
input_curl_seek
(
InputStream
*
is
,
InputPlugin
::
offset_type
offset
,
int
whence
,
Error
&
error
)
inline
bool
CurlInputStream
::
Seek
(
InputPlugin
::
offset_type
offset
,
int
whence
,
Error
&
error
)
{
CurlInputStream
*
c
=
(
CurlInputStream
*
)
is
;
bool
ret
;
assert
(
is
->
ready
);
assert
(
base
.
ready
);
if
(
whence
==
SEEK_SET
&&
offset
==
is
->
offset
)
if
(
whence
==
SEEK_SET
&&
offset
==
base
.
offset
)
/* no-op */
return
true
;
if
(
!
is
->
seekable
)
if
(
!
base
.
seekable
)
return
false
;
/* calculate the absolute offset */
...
...
@@ -1087,15 +1085,15 @@ input_curl_seek(InputStream *is, InputPlugin::offset_type offset,
break
;
case
SEEK_CUR
:
offset
+=
is
->
offset
;
offset
+=
base
.
offset
;
break
;
case
SEEK_END
:
if
(
is
->
size
<
0
)
if
(
base
.
size
<
0
)
/* stream size is not known */
return
false
;
offset
+=
is
->
size
;
offset
+=
base
.
size
;
break
;
default
:
...
...
@@ -1107,67 +1105,75 @@ input_curl_seek(InputStream *is, InputPlugin::offset_type offset,
/* check if we can fast-forward the buffer */
while
(
offset
>
is
->
offset
&&
!
c
->
buffers
.
empty
())
{
auto
&
buffer
=
c
->
buffers
.
front
();
while
(
offset
>
base
.
offset
&&
!
buffers
.
empty
())
{
auto
&
buffer
=
buffers
.
front
();
size_t
length
=
buffer
.
Available
();
if
(
offset
-
is
->
offset
<
(
InputPlugin
::
offset_type
)
length
)
length
=
offset
-
is
->
offset
;
if
(
offset
-
base
.
offset
<
(
InputPlugin
::
offset_type
)
length
)
length
=
offset
-
base
.
offset
;
const
bool
empty
=
!
buffer
.
Consume
(
length
);
if
(
empty
)
c
->
buffers
.
pop_front
();
buffers
.
pop_front
();
is
->
offset
+=
length
;
base
.
offset
+=
length
;
}
if
(
offset
==
is
->
offset
)
if
(
offset
==
base
.
offset
)
return
true
;
/* close the old connection and open a new one */
c
->
base
.
mutex
.
unlock
();
base
.
mutex
.
unlock
();
c
->
FreeEasyIndirect
();
c
->
buffers
.
clear
();
FreeEasyIndirect
();
buffers
.
clear
();
is
->
offset
=
offset
;
if
(
is
->
offset
==
is
->
size
)
{
base
.
offset
=
offset
;
if
(
base
.
offset
==
base
.
size
)
{
/* seek to EOF: simulate empty result; avoid
triggering a "416 Requested Range Not Satisfiable"
response */
return
true
;
}
ret
=
c
->
InitEasy
(
error
);
if
(
!
ret
)
if
(
!
InitEasy
(
error
))
return
false
;
/* send the "Range" header */
if
(
is
->
offset
>
0
)
{
sprintf
(
c
->
range
,
"%lld-"
,
(
long
long
)
is
->
offset
);
curl_easy_setopt
(
c
->
easy
,
CURLOPT_RANGE
,
c
->
range
);
if
(
base
.
offset
>
0
)
{
sprintf
(
range
,
"%lld-"
,
(
long
long
)
base
.
offset
);
curl_easy_setopt
(
easy
,
CURLOPT_RANGE
,
range
);
}
c
->
base
.
ready
=
false
;
base
.
ready
=
false
;
if
(
!
input_curl_easy_add_indirect
(
c
,
error
))
if
(
!
input_curl_easy_add_indirect
(
this
,
error
))
return
false
;
c
->
base
.
mutex
.
lock
();
base
.
mutex
.
lock
();
while
(
!
c
->
base
.
ready
)
c
->
base
.
cond
.
wait
(
c
->
base
.
mutex
);
while
(
!
base
.
ready
)
base
.
cond
.
wait
(
base
.
mutex
);
if
(
c
->
postponed_error
.
IsDefined
())
{
error
=
std
::
move
(
c
->
postponed_error
);
c
->
postponed_error
.
Clear
();
if
(
postponed_error
.
IsDefined
())
{
error
=
std
::
move
(
postponed_error
);
postponed_error
.
Clear
();
return
false
;
}
return
true
;
}
static
bool
input_curl_seek
(
InputStream
*
is
,
InputPlugin
::
offset_type
offset
,
int
whence
,
Error
&
error
)
{
CurlInputStream
&
c
=
*
(
CurlInputStream
*
)
is
;
return
c
.
Seek
(
offset
,
whence
,
error
);
}
static
InputStream
*
input_curl_open
(
const
char
*
url
,
Mutex
&
mutex
,
Cond
&
cond
,
Error
&
error
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment