Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Unified Diff: base/unix_domain_socket_posix.cc

Issue 131006: Linux: move SyncIPC function from Skia to base. (Closed)
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/unix_domain_socket_posix.cc
diff --git a/base/unix_domain_socket_posix.cc b/base/unix_domain_socket_posix.cc
index 55cb18611521657905e8bf6ef114d7bf2038090b..c311eddd5c197ad389e836abe4a9a495bd5e9e2d 100644
--- a/base/unix_domain_socket_posix.cc
+++ b/base/unix_domain_socket_posix.cc
@@ -10,6 +10,7 @@
#include "base/eintr_wrapper.h"
#include "base/logging.h"
+#include "base/pickle.h"
namespace base {
@@ -94,4 +95,45 @@ ssize_t RecvMsg(int fd, void* buf, size_t length, std::vector<int>* fds) {
return r;
}
+ssize_t SendRecvMsg(int fd, uint8_t* reply, unsigned reply_len, int* result_fd,
+ const Pickle& request) {
+ int fds[2];
Evan Martin 2009/06/18 00:36:08 2spc tabs comment in here that this socketpair is
+ if (socketpair(AF_UNIX, SOCK_DGRAM, 0, fds) == -1)
+ return false;
+
+ std::vector<int> fd_vector;
+ fd_vector.push_back(fds[1]);
+ if (!SendMsg(fd, request.data(), request.size(), fd_vector)) {
+ close(fds[0]);
+ close(fds[1]);
+ return -1;
+ }
+ close(fds[1]);
+
+ fd_vector.clear();
+ const ssize_t r = RecvMsg(fds[0], reply, reply_len, &fd_vector);
Evan Martin 2009/06/18 00:36:08 would be nice to not use a single letter variable
+ close(fds[0]);
+ if (r == -1)
+ return -1;
+
+ if ((fd_vector.size() > 0 && result_fd == NULL) || fd_vector.size() > 1) {
Evan Martin 2009/06/18 00:36:08 It seems these sorts of errors are not like the Se
+ for (std::vector<int>::const_iterator
+ i = fd_vector.begin(); i != fd_vector.end(); ++i) {
+ close(*i);
+ }
+
+ return -1;
+ }
+
+ if (result_fd) {
+ if (fd_vector.size() == 0) {
+ *result_fd = -1;
+ } else {
+ *result_fd = fd_vector[0];
+ }
+ }
+
+ return r;
+}
+
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698