| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/embedder/platform_channel_pair.h" | 5 #include "mojo/embedder/platform_channel_pair.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <signal.h> | 8 #include <signal.h> |
| 9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| 11 #include <sys/uio.h> |
| 11 #include <unistd.h> | 12 #include <unistd.h> |
| 12 | 13 |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "build/build_config.h" | 16 #include "mojo/embedder/platform_channel_utils_posix.h" |
| 16 #include "mojo/embedder/scoped_platform_handle.h" | 17 #include "mojo/embedder/scoped_platform_handle.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace mojo { | 20 namespace mojo { |
| 20 namespace embedder { | 21 namespace embedder { |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 class PlatformChannelPairPosixTest : public testing::Test { | 24 class PlatformChannelPairPosixTest : public testing::Test { |
| 24 public: | 25 public: |
| 25 PlatformChannelPairPosixTest() {} | 26 PlatformChannelPairPosixTest() {} |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 read(server_handle.get().fd, buffer, sizeof(buffer))); | 64 read(server_handle.get().fd, buffer, sizeof(buffer))); |
| 64 EXPECT_STREQ(kHello, buffer); | 65 EXPECT_STREQ(kHello, buffer); |
| 65 | 66 |
| 66 // Try reading again. | 67 // Try reading again. |
| 67 ssize_t result = read(server_handle.get().fd, buffer, sizeof(buffer)); | 68 ssize_t result = read(server_handle.get().fd, buffer, sizeof(buffer)); |
| 68 // We should probably get zero (for "end of file"), but -1 would also be okay. | 69 // We should probably get zero (for "end of file"), but -1 would also be okay. |
| 69 EXPECT_TRUE(result == 0 || result == -1); | 70 EXPECT_TRUE(result == 0 || result == -1); |
| 70 if (result == -1) | 71 if (result == -1) |
| 71 PLOG(WARNING) << "read (expected 0 for EOF)"; | 72 PLOG(WARNING) << "read (expected 0 for EOF)"; |
| 72 | 73 |
| 73 // However, |write()|/|send()| should fail outright. | 74 // Test our replacement for |write()|/|send()|. |
| 74 // On Mac, |SIGPIPE| needs to be suppressed on the socket itself and we can | 75 result = PlatformChannelWrite(server_handle.get(), kHello, sizeof(kHello)); |
| 75 // use |write()|/|writev()|. On Linux, we have to suppress it by using | |
| 76 // |send()|/|sendmsg()| with |MSG_NOSIGNAL|. | |
| 77 #if defined(OS_MACOSX) | |
| 78 result = write(server_handle.get().fd, kHello, sizeof(kHello)); | |
| 79 #else | |
| 80 result = send(server_handle.get().fd, kHello, sizeof(kHello), MSG_NOSIGNAL); | |
| 81 #endif | |
| 82 EXPECT_EQ(-1, result); | 76 EXPECT_EQ(-1, result); |
| 83 if (errno != EPIPE) | 77 if (errno != EPIPE) |
| 84 PLOG(WARNING) << "write (expected EPIPE)"; | 78 PLOG(WARNING) << "write (expected EPIPE)"; |
| 79 |
| 80 // Test our replacement for |writev()|/|sendv()|. |
| 81 struct iovec iov[2] = { |
| 82 { const_cast<char*>(kHello), sizeof(kHello) }, |
| 83 { const_cast<char*>(kHello), sizeof(kHello) } |
| 84 }; |
| 85 result = PlatformChannelWritev(server_handle.get(), iov, 2); |
| 86 EXPECT_EQ(-1, result); |
| 87 if (errno != EPIPE) |
| 88 PLOG(WARNING) << "write (expected EPIPE)"; |
| 85 } | 89 } |
| 86 | 90 |
| 87 } // namespace | 91 } // namespace |
| 88 } // namespace embedder | 92 } // namespace embedder |
| 89 } // namespace mojo | 93 } // namespace mojo |
| OLD | NEW |