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
0626e3d2
Commit
0626e3d2
authored
May 16, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
input/buffering: at end of input, seek to first hole
parent
869d2150
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
1 deletion
+40
-1
BufferingInputStream.cxx
src/input/BufferingInputStream.cxx
+36
-1
BufferingInputStream.hxx
src/input/BufferingInputStream.hxx
+4
-0
No files found.
src/input/BufferingInputStream.cxx
View file @
0626e3d2
...
...
@@ -127,6 +127,22 @@ BufferingInputStream::Read(std::unique_lock<Mutex> &lock, void *ptr, size_t s)
}
}
size_t
BufferingInputStream
::
FindFirstHole
()
const
noexcept
{
auto
r
=
buffer
.
Read
(
0
);
if
(
r
.
undefined_size
>
0
)
/* a hole at the beginning */
return
0
;
if
(
r
.
defined_buffer
.
size
<
size
())
/* a hole in the middle */
return
r
.
defined_buffer
.
size
;
/* the file has been read completely */
return
INVALID_OFFSET
;
}
void
BufferingInputStream
::
RunThread
()
noexcept
{
...
...
@@ -173,7 +189,26 @@ BufferingInputStream::RunThread() noexcept
client_cond
.
notify_one
();
OnBufferAvailable
();
}
}
else
if
(
input
->
IsAvailable
()
&&
!
input
->
IsEOF
())
{
}
else
if
(
input
->
IsEOF
())
{
/* our input has reached its end: prepare
reading the first remaining hole */
size_t
new_offset
=
FindFirstHole
();
if
(
new_offset
==
INVALID_OFFSET
)
{
/* the file has been read completely */
wake_cond
.
wait
(
lock
);
continue
;
}
/* seek to the first hole */
try
{
input
->
Seek
(
lock
,
new_offset
);
}
catch
(...)
{
read_error
=
std
::
current_exception
();
client_cond
.
notify_one
();
OnBufferAvailable
();
}
}
else
if
(
input
->
IsAvailable
())
{
const
auto
read_offset
=
input
->
GetOffset
();
auto
w
=
buffer
.
Write
(
read_offset
);
...
...
src/input/BufferingInputStream.hxx
View file @
0626e3d2
...
...
@@ -63,6 +63,8 @@ class BufferingInputStream : InputStreamHandler {
std
::
exception_ptr
read_error
,
seek_error
;
static
constexpr
size_t
INVALID_OFFSET
=
~
size_t
(
0
);
public
:
explicit
BufferingInputStream
(
InputStreamPtr
_input
);
~
BufferingInputStream
()
noexcept
;
...
...
@@ -84,6 +86,8 @@ protected:
virtual
void
OnBufferAvailable
()
noexcept
{}
private
:
size_t
FindFirstHole
()
const
noexcept
;
void
RunThread
()
noexcept
;
/* virtual methods from class InputStreamHandler */
...
...
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