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
979a7a1d
Commit
979a7a1d
authored
Sep 07, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test/run_input: add option --chunk-size
parent
962cf32b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
4 deletions
+29
-4
run_input.cxx
test/run_input.cxx
+29
-4
No files found.
test/run_input.cxx
View file @
979a7a1d
...
...
@@ -49,11 +49,15 @@
#include <unistd.h>
#include <stdlib.h>
static
constexpr
std
::
size_t
MAX_CHUNK_SIZE
=
16384
;
struct
CommandLine
{
const
char
*
uri
=
nullptr
;
FromNarrowPath
config_path
;
std
::
size_t
chunk_size
=
MAX_CHUNK_SIZE
;
bool
verbose
=
false
;
bool
scan
=
false
;
...
...
@@ -63,14 +67,27 @@ enum Option {
OPTION_CONFIG
,
OPTION_VERBOSE
,
OPTION_SCAN
,
OPTION_CHUNK_SIZE
,
};
static
constexpr
OptionDef
option_defs
[]
=
{
{
"config"
,
0
,
true
,
"Load a MPD configuration file"
},
{
"verbose"
,
'v'
,
false
,
"Verbose logging"
},
{
"scan"
,
0
,
false
,
"Scan tags instead of reading raw data"
},
{
"chunk-size"
,
0
,
true
,
"Read this number of bytes at a time"
},
};
static
std
::
size_t
ParseSize
(
const
char
*
s
)
{
char
*
endptr
;
std
::
size_t
value
=
std
::
strtoul
(
s
,
&
endptr
,
10
);
if
(
endptr
==
s
)
throw
std
::
runtime_error
(
"Failed to parse integer"
);
return
value
;
}
static
CommandLine
ParseCommandLine
(
int
argc
,
char
**
argv
)
{
...
...
@@ -90,6 +107,12 @@ ParseCommandLine(int argc, char **argv)
case
OPTION_SCAN
:
c
.
scan
=
true
;
break
;
case
OPTION_CHUNK_SIZE
:
c
.
chunk_size
=
ParseSize
(
o
.
value
);
if
(
c
.
chunk_size
<=
0
||
c
.
chunk_size
>
MAX_CHUNK_SIZE
)
throw
std
::
runtime_error
(
"Invalid chunk size"
);
break
;
}
}
...
...
@@ -130,7 +153,7 @@ tag_save(FILE *file, const Tag &tag)
}
static
int
dump_input_stream
(
InputStream
&
is
,
FileDescriptor
out
)
dump_input_stream
(
InputStream
&
is
,
FileDescriptor
out
,
size_t
chunk_size
)
{
const
std
::
lock_guard
<
Mutex
>
protect
(
is
.
mutex
);
...
...
@@ -150,8 +173,9 @@ dump_input_stream(InputStream &is, FileDescriptor out)
}
}
char
buffer
[
4096
];
size_t
num_read
=
is
.
Read
(
buffer
,
sizeof
(
buffer
));
char
buffer
[
MAX_CHUNK_SIZE
];
assert
(
chunk_size
<=
sizeof
(
buffer
));
size_t
num_read
=
is
.
Read
(
buffer
,
chunk_size
);
if
(
num_read
==
0
)
break
;
...
...
@@ -232,7 +256,8 @@ try {
Mutex
mutex
;
auto
is
=
InputStream
::
OpenReady
(
c
.
uri
,
mutex
);
return
dump_input_stream
(
*
is
,
FileDescriptor
(
STDOUT_FILENO
));
return
dump_input_stream
(
*
is
,
FileDescriptor
(
STDOUT_FILENO
),
c
.
chunk_size
);
}
catch
(...)
{
PrintException
(
std
::
current_exception
());
return
EXIT_FAILURE
;
...
...
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