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
a72878c5
Commit
a72878c5
authored
5 years ago
by
Max Kellermann
Committed by
Max Kellermann
5 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
io/FileDescriptor: add method FullRead()
parent
bd4df1ae
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
18 deletions
+29
-18
FileDescriptor.cxx
src/system/FileDescriptor.cxx
+21
-1
FileDescriptor.hxx
src/system/FileDescriptor.hxx
+7
-1
run_filter.cxx
test/run_filter.cxx
+1
-16
No files found.
src/system/FileDescriptor.cxx
View file @
a72878c5
/*
/*
* Copyright 2012-201
8
Max Kellermann <max.kellermann@gmail.com>
* Copyright 2012-201
9
Max Kellermann <max.kellermann@gmail.com>
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
@@ -28,8 +28,10 @@
...
@@ -28,8 +28,10 @@
*/
*/
#include "FileDescriptor.hxx"
#include "FileDescriptor.hxx"
#include "system/Error.hxx"
#include <assert.h>
#include <assert.h>
#include <stdint.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <fcntl.h>
...
@@ -285,6 +287,24 @@ FileDescriptor::GetSize() const noexcept
...
@@ -285,6 +287,24 @@ FileDescriptor::GetSize() const noexcept
:
-
1
;
:
-
1
;
}
}
void
FileDescriptor
::
FullRead
(
void
*
_buffer
,
size_t
length
)
{
uint8_t
*
buffer
=
(
uint8_t
*
)
_buffer
;
while
(
length
>
0
)
{
ssize_t
nbytes
=
Read
(
buffer
,
length
);
if
(
nbytes
<=
0
)
{
if
(
nbytes
<
0
)
throw
MakeErrno
(
"Failed to read"
);
throw
std
::
runtime_error
(
"Unexpected end of file"
);
}
buffer
+=
nbytes
;
length
-=
nbytes
;
}
}
#ifndef _WIN32
#ifndef _WIN32
int
int
...
...
This diff is collapsed.
Click to expand it.
src/system/FileDescriptor.hxx
View file @
a72878c5
/*
/*
* Copyright 2012-201
8
Max Kellermann <max.kellermann@gmail.com>
* Copyright 2012-201
9
Max Kellermann <max.kellermann@gmail.com>
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
@@ -233,6 +233,12 @@ public:
...
@@ -233,6 +233,12 @@ public:
return
::
read
(
fd
,
buffer
,
length
);
return
::
read
(
fd
,
buffer
,
length
);
}
}
/**
* Read until all of the given buffer has been filled. Throws
* on error.
*/
void
FullRead
(
void
*
buffer
,
size_t
length
);
ssize_t
Write
(
const
void
*
buffer
,
size_t
length
)
noexcept
{
ssize_t
Write
(
const
void
*
buffer
,
size_t
length
)
noexcept
{
return
::
write
(
fd
,
buffer
,
length
);
return
::
write
(
fd
,
buffer
,
length
);
}
}
...
...
This diff is collapsed.
Click to expand it.
test/run_filter.cxx
View file @
a72878c5
...
@@ -80,21 +80,6 @@ WriteOrThrow(FileDescriptor fd, const void *buffer, size_t size)
...
@@ -80,21 +80,6 @@ WriteOrThrow(FileDescriptor fd, const void *buffer, size_t size)
}
}
static
void
static
void
FullRead
(
FileDescriptor
fd
,
void
*
_buffer
,
size_t
size
)
{
auto
buffer
=
(
uint8_t
*
)
_buffer
;
while
(
size
>
0
)
{
size_t
nbytes
=
ReadOrThrow
(
fd
,
buffer
,
size
);
if
(
nbytes
==
0
)
throw
std
::
runtime_error
(
"Premature end of input"
);
buffer
+=
nbytes
;
size
-=
nbytes
;
}
}
static
void
FullWrite
(
FileDescriptor
fd
,
ConstBuffer
<
uint8_t
>
src
)
FullWrite
(
FileDescriptor
fd
,
ConstBuffer
<
uint8_t
>
src
)
{
{
while
(
!
src
.
empty
())
{
while
(
!
src
.
empty
())
{
...
@@ -124,7 +109,7 @@ ReadFrames(FileDescriptor fd, void *_buffer, size_t size, size_t frame_size)
...
@@ -124,7 +109,7 @@ ReadFrames(FileDescriptor fd, void *_buffer, size_t size, size_t frame_size)
const
size_t
modulo
=
nbytes
%
frame_size
;
const
size_t
modulo
=
nbytes
%
frame_size
;
if
(
modulo
>
0
)
{
if
(
modulo
>
0
)
{
size_t
rest
=
frame_size
-
modulo
;
size_t
rest
=
frame_size
-
modulo
;
FullRead
(
fd
,
buffer
+
nbytes
,
rest
);
fd
.
FullRead
(
buffer
+
nbytes
,
rest
);
nbytes
+=
rest
;
nbytes
+=
rest
;
}
}
...
...
This diff is collapsed.
Click to expand it.
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