diff options
author | Josh Gao | 2017-08-25 20:00:18 -0500 |
---|---|---|
committer | Josh Gao | 2017-08-28 16:51:07 -0500 |
commit | fdf832dfd3b2f1be9d3ba831ff85b323a61ee8a3 (patch) | |
tree | 41f7132b05979b0187f91f264f45911f78015ea6 /base/include/android-base | |
parent | 75a40988c0e7a35f2663b644989ce012b66f4586 (diff) | |
download | platform-system-core-fdf832dfd3b2f1be9d3ba831ff85b323a61ee8a3.tar.gz platform-system-core-fdf832dfd3b2f1be9d3ba831ff85b323a61ee8a3.tar.xz platform-system-core-fdf832dfd3b2f1be9d3ba831ff85b323a61ee8a3.zip |
base: add Pipe and Socketpair wrappers.
Also, switch debuggerd_handler over to using android::base::unique_fd.
Test: treehugger
Change-Id: I97b2ce22f1795ce1c4370f95d00d769846cc54b8
Diffstat (limited to 'base/include/android-base')
-rw-r--r-- | base/include/android-base/unique_fd.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/base/include/android-base/unique_fd.h b/base/include/android-base/unique_fd.h index 6cfcfcd37..fb3ddedaa 100644 --- a/base/include/android-base/unique_fd.h +++ b/base/include/android-base/unique_fd.h | |||
@@ -17,6 +17,13 @@ | |||
17 | #ifndef ANDROID_BASE_UNIQUE_FD_H | 17 | #ifndef ANDROID_BASE_UNIQUE_FD_H |
18 | #define ANDROID_BASE_UNIQUE_FD_H | 18 | #define ANDROID_BASE_UNIQUE_FD_H |
19 | 19 | ||
20 | #include <fcntl.h> | ||
21 | |||
22 | #if !defined(_WIN32) | ||
23 | #include <sys/socket.h> | ||
24 | #endif | ||
25 | |||
26 | #include <sys/types.h> | ||
20 | #include <unistd.h> | 27 | #include <unistd.h> |
21 | 28 | ||
22 | // DO NOT INCLUDE OTHER LIBBASE HEADERS! | 29 | // DO NOT INCLUDE OTHER LIBBASE HEADERS! |
@@ -88,6 +95,35 @@ class unique_fd_impl final { | |||
88 | 95 | ||
89 | using unique_fd = unique_fd_impl<DefaultCloser>; | 96 | using unique_fd = unique_fd_impl<DefaultCloser>; |
90 | 97 | ||
98 | #if !defined(_WIN32) | ||
99 | |||
100 | // Inline functions, so that they can be used header-only. | ||
101 | inline bool Pipe(unique_fd* read, unique_fd* write) { | ||
102 | int pipefd[2]; | ||
103 | if (pipe2(pipefd, O_CLOEXEC) != 0) { | ||
104 | return false; | ||
105 | } | ||
106 | read->reset(pipefd[0]); | ||
107 | write->reset(pipefd[1]); | ||
108 | return true; | ||
109 | } | ||
110 | |||
111 | inline bool Socketpair(int domain, int type, int protocol, unique_fd* left, unique_fd* right) { | ||
112 | int sockfd[2]; | ||
113 | if (socketpair(domain, type, protocol, sockfd) != 0) { | ||
114 | return false; | ||
115 | } | ||
116 | left->reset(sockfd[0]); | ||
117 | right->reset(sockfd[1]); | ||
118 | return true; | ||
119 | } | ||
120 | |||
121 | inline bool Socketpair(int type, unique_fd* left, unique_fd* right) { | ||
122 | return Socketpair(AF_UNIX, type, 0, left, right); | ||
123 | } | ||
124 | |||
125 | #endif // !defined(_WIN32) | ||
126 | |||
91 | } // namespace base | 127 | } // namespace base |
92 | } // namespace android | 128 | } // namespace android |
93 | 129 | ||