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
8106929d
Commit
8106929d
authored
Aug 20, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
system/FileDescriptor: add pipe2() wrapper
parent
795baed3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
18 deletions
+31
-18
FileDescriptor.cxx
src/system/FileDescriptor.cxx
+26
-18
FileDescriptor.hxx
src/system/FileDescriptor.hxx
+5
-0
No files found.
src/system/FileDescriptor.cxx
View file @
8106929d
...
...
@@ -115,15 +115,33 @@ FileDescriptor::OpenNonBlocking(const char *pathname) noexcept
#endif
#ifdef __linux__
bool
FileDescriptor
::
CreatePipe
(
FileDescriptor
&
r
,
FileDescriptor
&
w
)
noexcept
FileDescriptor
::
CreatePipe
(
FileDescriptor
&
r
,
FileDescriptor
&
w
,
int
flags
)
noexcept
{
int
fds
[
2
];
const
int
result
=
pipe2
(
fds
,
flags
);
if
(
result
<
0
)
return
false
;
r
=
FileDescriptor
(
fds
[
0
]);
w
=
FileDescriptor
(
fds
[
1
]);
return
true
;
}
#endif
bool
FileDescriptor
::
CreatePipe
(
FileDescriptor
&
r
,
FileDescriptor
&
w
)
noexcept
{
#ifdef __linux__
const
int
flags
=
O_CLOEXEC
;
const
int
result
=
pipe2
(
fds
,
flags
);
#elif defined(_WIN32)
return
CreatePipe
(
r
,
w
,
O_CLOEXEC
);
#else
int
fds
[
2
];
#ifdef _WIN32
const
int
result
=
_pipe
(
fds
,
512
,
_O_BINARY
);
#else
const
int
result
=
pipe
(
fds
);
...
...
@@ -135,6 +153,7 @@ FileDescriptor::CreatePipe(FileDescriptor &r, FileDescriptor &w) noexcept
r
=
FileDescriptor
(
fds
[
0
]);
w
=
FileDescriptor
(
fds
[
1
]);
return
true
;
#endif
}
#ifndef _WIN32
...
...
@@ -143,27 +162,16 @@ bool
FileDescriptor
::
CreatePipeNonBlock
(
FileDescriptor
&
r
,
FileDescriptor
&
w
)
noexcept
{
int
fds
[
2
];
#ifdef __linux__
const
int
flags
=
O_CLOEXEC
|
O_NONBLOCK
;
const
int
result
=
pipe2
(
fds
,
flags
);
return
CreatePipe
(
r
,
w
,
O_CLOEXEC
|
O_NONBLOCK
);
#else
const
int
result
=
pipe
(
fds
);
#endif
if
(
result
<
0
)
if
(
!
CreatePipe
(
r
,
w
))
return
false
;
r
=
FileDescriptor
(
fds
[
0
]);
w
=
FileDescriptor
(
fds
[
1
]);
#ifndef __linux__
r
.
SetNonBlocking
();
w
.
SetNonBlocking
();
#endif
return
true
;
#endif
}
void
...
...
src/system/FileDescriptor.hxx
View file @
8106929d
...
...
@@ -129,6 +129,11 @@ public:
bool
OpenNonBlocking
(
const
char
*
pathname
)
noexcept
;
#endif
#ifdef __linux__
static
bool
CreatePipe
(
FileDescriptor
&
r
,
FileDescriptor
&
w
,
int
flags
)
noexcept
;
#endif
static
bool
CreatePipe
(
FileDescriptor
&
r
,
FileDescriptor
&
w
)
noexcept
;
#ifdef _WIN32
...
...
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