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
cd352716
Commit
cd352716
authored
Mar 22, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/io/BufferedOutputStream: add code comments
parent
7b575f61
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
+23
-0
BufferedOutputStream.cxx
src/fs/io/BufferedOutputStream.cxx
+5
-0
BufferedOutputStream.hxx
src/fs/io/BufferedOutputStream.hxx
+18
-0
No files found.
src/fs/io/BufferedOutputStream.cxx
View file @
cd352716
...
...
@@ -41,17 +41,22 @@ bool
BufferedOutputStream
::
Write
(
const
void
*
data
,
size_t
size
)
{
if
(
gcc_unlikely
(
last_error
.
IsDefined
()))
/* the stream has already failed */
return
false
;
/* try to append to the current buffer */
if
(
AppendToBuffer
(
data
,
size
))
return
true
;
/* not enough room in the buffer - flush it */
if
(
!
Flush
())
return
false
;
/* see if there's now enough room */
if
(
AppendToBuffer
(
data
,
size
))
return
true
;
/* too large for the buffer: direct write */
return
os
.
Write
(
data
,
size
,
last_error
);
}
...
...
src/fs/io/BufferedOutputStream.hxx
View file @
cd352716
...
...
@@ -30,6 +30,14 @@
class
OutputStream
;
class
Error
;
/**
* An #OutputStream wrapper that buffers its output to reduce the
* number of OutputStream::Write() calls.
*
* It simplifies error handling by managing an #Error attribute.
* Invoke any number of writes, and check for errors in the end using
* Check().
*/
class
BufferedOutputStream
{
OutputStream
&
os
;
...
...
@@ -47,11 +55,18 @@ public:
gcc_printf
(
2
,
3
)
bool
Format
(
const
char
*
fmt
,
...);
/**
* Returns false if an error has occurred.
*/
gcc_pure
bool
Check
()
const
{
return
!
last_error
.
IsDefined
();
}
/**
* Returns false if an error has occurred. In that case, a
* copy of the #Error is returned.
*/
bool
Check
(
Error
&
error
)
const
{
if
(
last_error
.
IsDefined
())
{
error
.
Set
(
last_error
);
...
...
@@ -60,6 +75,9 @@ public:
return
true
;
}
/**
* Write buffer contents to the #OutputStream.
*/
bool
Flush
();
bool
Flush
(
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