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

Side by Side 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, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/embedder/platform_channel_utils_posix.h ('k') | mojo/mojo.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/embedder/platform_channel_utils_posix.h"
6
7 #include <sys/socket.h>
8 #include <sys/uio.h>
9 #include <unistd.h>
10
11 #include "base/posix/eintr_wrapper.h"
12 #include "build/build_config.h"
13
14 namespace mojo {
15 namespace embedder {
16
17 // On Linux, |SIGPIPE| is suppressed by passing |MSG_NOSIGNAL| to
18 // |send()|/|sendmsg()|. (There is no way of suppressing |SIGPIPE| on
19 // |write()|/|writev().) On Mac, |SIGPIPE| is suppressed by setting the
20 // |SO_NOSIGPIPE| option on the socket.
21 //
22 // Performance notes:
23 // - On Linux, we have to use |send()|/|sendmsg()| rather than
24 // |write()|/|writev()| in order to suppress |SIGPIPE|. This is okay, since
25 // |send()| is (slightly) faster than |write()| (!), while |sendmsg()| is
26 // quite comparable to |writev()|.
27 // - On Mac, we may use |write()|/|writev()|. Here, |write()| is considerably
28 // faster than |send()|, whereas |sendmsg()| is quite comparable to
29 // |writev()|.
30 // - On both platforms, an appropriate |sendmsg()|/|writev()| is considerably
31 // faster than two |send()|s/|write()|s.
32 // - Relative numbers (minimum real times from 10 runs) for one |write()| of
33 // 1032 bytes, one |send()| of 1032 bytes, one |writev()| of 32+1000 bytes,
34 // one |sendmsg()| of 32+1000 bytes, two |write()|s of 32 and 1000 bytes, two
35 // |send()|s of 32 and 1000 bytes:
36 // - Linux: 0.81 s, 0.77 s, 0.87 s, 0.89 s, 1.31 s, 1.22 s
37 // - Mac: 2.21 s, 2.91 s, 2.98 s, 3.08 s, 3.59 s, 4.74 s
38
39 ssize_t PlatformChannelWrite(PlatformHandle h,
40 const void* bytes,
41 size_t num_bytes) {
42 #if defined(OS_MACOSX)
43 return HANDLE_EINTR(write(h.fd, bytes, num_bytes));
44 #else
45 return send(h.fd, bytes, num_bytes, MSG_NOSIGNAL);
46 #endif
47 }
48
49 ssize_t PlatformChannelWritev(PlatformHandle h,
50 struct iovec* iov,
51 size_t num_iov) {
52 #if defined(OS_MACOSX)
53 return HANDLE_EINTR(writev(h.fd, iov, static_cast<int>(num_iov)));
54 #else
55 struct msghdr msg = {};
56 msg.msg_iov = iov;
57 msg.msg_iovlen = num_iov;
58 return HANDLE_EINTR(sendmsg(h.fd, &msg, MSG_NOSIGNAL));
59 #endif
60 }
61
62 } // namespace embedder
63 } // namespace mojo
OLDNEW
« 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