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

Unified Diff: mojo/embedder/platform_channel_utils_posix.cc

Issue 226263005: Mojo: Abstract out write/writev vs send/sendmsg (for Unix domain sockets). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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
« no previous file with comments | « mojo/embedder/platform_channel_utils_posix.h ('k') | mojo/mojo.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/embedder/platform_channel_utils_posix.cc
diff --git a/mojo/embedder/platform_channel_utils_posix.cc b/mojo/embedder/platform_channel_utils_posix.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f0e05387745a2c084a266b29773f2d2d461d222f
--- /dev/null
+++ b/mojo/embedder/platform_channel_utils_posix.cc
@@ -0,0 +1,63 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/embedder/platform_channel_utils_posix.h"
+
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <unistd.h>
+
+#include "base/posix/eintr_wrapper.h"
+#include "build/build_config.h"
+
+namespace mojo {
+namespace embedder {
+
+// On Linux, |SIGPIPE| is suppressed by passing |MSG_NOSIGNAL| to
+// |send()|/|sendmsg()|. (There is no way of suppressing |SIGPIPE| on
+// |write()|/|writev().) On Mac, |SIGPIPE| is suppressed by setting the
+// |SO_NOSIGPIPE| option on the socket.
+//
+// Performance notes:
+// - On Linux, we have to use |send()|/|sendmsg()| rather than
+// |write()|/|writev()| in order to suppress |SIGPIPE|. This is okay, since
+// |send()| is (slightly) faster than |write()| (!), while |sendmsg()| is
+// quite comparable to |writev()|.
+// - On Mac, we may use |write()|/|writev()|. Here, |write()| is considerably
+// faster than |send()|, whereas |sendmsg()| is quite comparable to
+// |writev()|.
+// - On both platforms, an appropriate |sendmsg()|/|writev()| is considerably
+// faster than two |send()|s/|write()|s.
+// - Relative numbers (minimum real times from 10 runs) for one |write()| of
+// 1032 bytes, one |send()| of 1032 bytes, one |writev()| of 32+1000 bytes,
+// one |sendmsg()| of 32+1000 bytes, two |write()|s of 32 and 1000 bytes, two
+// |send()|s of 32 and 1000 bytes:
+// - Linux: 0.81 s, 0.77 s, 0.87 s, 0.89 s, 1.31 s, 1.22 s
+// - Mac: 2.21 s, 2.91 s, 2.98 s, 3.08 s, 3.59 s, 4.74 s
+
+ssize_t PlatformChannelWrite(PlatformHandle h,
+ const void* bytes,
+ size_t num_bytes) {
+#if defined(OS_MACOSX)
+ return HANDLE_EINTR(write(h.fd, bytes, num_bytes));
+#else
+ return send(h.fd, bytes, num_bytes, MSG_NOSIGNAL);
+#endif
+}
+
+ssize_t PlatformChannelWritev(PlatformHandle h,
+ struct iovec* iov,
+ size_t num_iov) {
+#if defined(OS_MACOSX)
+ return HANDLE_EINTR(writev(h.fd, iov, static_cast<int>(num_iov)));
+#else
+ struct msghdr msg = {};
+ msg.msg_iov = iov;
+ msg.msg_iovlen = num_iov;
+ return HANDLE_EINTR(sendmsg(h.fd, &msg, MSG_NOSIGNAL));
+#endif
+}
+
+} // namespace embedder
+} // namespace mojo
« no previous file with comments | « mojo/embedder/platform_channel_utils_posix.h ('k') | mojo/mojo.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698