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

Side by Side Diff: mojo/edk/embedder/platform_channel_pair.cc

Issue 1659213002: Move PlatformChannelPair to //mojo/edk/platform and rename it PlatformPipe. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 10 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
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/edk/embedder/platform_channel_pair.h"
6
7 #include <fcntl.h>
8 #include <sys/socket.h>
9 #include <sys/types.h>
10 #include <unistd.h>
11
12 #include "base/logging.h"
13 #include "build/build_config.h"
14 #include "mojo/edk/platform/platform_handle.h"
15
16 using mojo::platform::PlatformHandle;
17
18 namespace mojo {
19 namespace embedder {
20
21 PlatformChannelPair::PlatformChannelPair() {
22 // Create the Unix domain socket and set the ends to nonblocking.
23 int fds[2];
24 // TODO(vtl): Maybe fail gracefully if |socketpair()| fails.
25 PCHECK(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0);
26 PCHECK(fcntl(fds[0], F_SETFL, O_NONBLOCK) == 0);
27 PCHECK(fcntl(fds[1], F_SETFL, O_NONBLOCK) == 0);
28
29 #if defined(OS_MACOSX)
30 // This turns off |SIGPIPE| when writing to a closed socket (causing it to
31 // fail with |EPIPE| instead). On Linux, we have to use |send...()| with
32 // |MSG_NOSIGNAL| -- which is not supported on Mac -- instead.
33 int no_sigpipe = 1;
34 PCHECK(setsockopt(fds[0], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe,
35 sizeof(no_sigpipe)) == 0);
36 PCHECK(setsockopt(fds[1], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe,
37 sizeof(no_sigpipe)) == 0);
38 #endif // defined(OS_MACOSX)
39
40 handle0.reset(PlatformHandle(fds[0]));
41 DCHECK(handle0.is_valid());
42 handle1.reset(PlatformHandle(fds[1]));
43 DCHECK(handle1.is_valid());
44 }
45
46 PlatformChannelPair::~PlatformChannelPair() {}
47
48 } // namespace embedder
49 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/platform_channel_pair.h ('k') | mojo/edk/embedder/platform_channel_pair_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698