OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <sys/socket.h> | 5 #include <sys/socket.h> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/posix/eintr_wrapper.h" | 10 #include "base/posix/eintr_wrapper.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 } | 101 } |
102 | 102 |
103 bool CreateServerSocket() { | 103 bool CreateServerSocket() { |
104 IPC::CreateServerUnixDomainSocket(socket_name_, &server_listen_fd_); | 104 IPC::CreateServerUnixDomainSocket(socket_name_, &server_listen_fd_); |
105 if (server_listen_fd_ < 0) | 105 if (server_listen_fd_ < 0) |
106 return false; | 106 return false; |
107 struct stat socket_stat; | 107 struct stat socket_stat; |
108 stat(socket_name_.value().c_str(), &socket_stat); | 108 stat(socket_name_.value().c_str(), &socket_stat); |
109 EXPECT_TRUE(S_ISSOCK(socket_stat.st_mode)); | 109 EXPECT_TRUE(S_ISSOCK(socket_stat.st_mode)); |
110 acceptor_.reset(new SocketAcceptor(server_listen_fd_, | 110 acceptor_.reset(new SocketAcceptor(server_listen_fd_, |
111 worker_.message_loop_proxy())); | 111 worker_.message_loop_proxy().get())); |
112 acceptor_->WaitUntilReady(); | 112 acceptor_->WaitUntilReady(); |
113 return true; | 113 return true; |
114 } | 114 } |
115 | 115 |
116 bool CreateClientSocket() { | 116 bool CreateClientSocket() { |
117 DCHECK(server_listen_fd_ >= 0); | 117 DCHECK(server_listen_fd_ >= 0); |
118 IPC::CreateClientUnixDomainSocket(socket_name_, &client_fd_); | 118 IPC::CreateClientUnixDomainSocket(socket_name_, &client_fd_); |
119 if (client_fd_ < 0) | 119 if (client_fd_ < 0) |
120 return false; | 120 return false; |
121 acceptor_->WaitForAccept(); | 121 acceptor_->WaitForAccept(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 HANDLE_EINTR(send(connection.client_fd(), buffer, buf_len, 0)); | 166 HANDLE_EINTR(send(connection.client_fd(), buffer, buf_len, 0)); |
167 ASSERT_EQ(buf_len, sent_bytes); | 167 ASSERT_EQ(buf_len, sent_bytes); |
168 char recv_buf[sizeof(buffer)]; | 168 char recv_buf[sizeof(buffer)]; |
169 size_t received_bytes = | 169 size_t received_bytes = |
170 HANDLE_EINTR(recv(connection.server_fd(), recv_buf, buf_len, 0)); | 170 HANDLE_EINTR(recv(connection.server_fd(), recv_buf, buf_len, 0)); |
171 ASSERT_EQ(buf_len, received_bytes); | 171 ASSERT_EQ(buf_len, received_bytes); |
172 ASSERT_EQ(0, memcmp(recv_buf, buffer, buf_len)); | 172 ASSERT_EQ(0, memcmp(recv_buf, buffer, buf_len)); |
173 } | 173 } |
174 | 174 |
175 } // namespace | 175 } // namespace |
OLD | NEW |