| 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 "ipc/unix_domain_socket_util.h" | 5 #include "ipc/unix_domain_socket_util.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <stddef.h> | |
| 9 #include <sys/socket.h> | 8 #include <sys/socket.h> |
| 10 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 11 #include <sys/un.h> | 10 #include <sys/un.h> |
| 12 #include <unistd.h> | 11 #include <unistd.h> |
| 13 | 12 |
| 14 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 16 #include "base/files/scoped_file.h" | 15 #include "base/files/scoped_file.h" |
| 17 #include "base/logging.h" | 16 #include "base/logging.h" |
| 18 #include "base/posix/eintr_wrapper.h" | 17 #include "base/posix/eintr_wrapper.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 110 } |
| 112 | 111 |
| 113 *server_listen_fd = fd.release(); | 112 *server_listen_fd = fd.release(); |
| 114 return true; | 113 return true; |
| 115 } | 114 } |
| 116 | 115 |
| 117 bool CreateClientUnixDomainSocket(const base::FilePath& socket_path, | 116 bool CreateClientUnixDomainSocket(const base::FilePath& socket_path, |
| 118 int* client_socket) { | 117 int* client_socket) { |
| 119 DCHECK(client_socket); | 118 DCHECK(client_socket); |
| 120 | 119 |
| 121 std::string socket_name = socket_path.value(); | |
| 122 base::FilePath socket_dir = socket_path.DirName(); | |
| 123 | |
| 124 struct sockaddr_un unix_addr; | 120 struct sockaddr_un unix_addr; |
| 125 size_t unix_addr_len; | 121 size_t unix_addr_len; |
| 126 base::ScopedFD fd( | 122 base::ScopedFD fd( |
| 127 MakeUnixAddrForPath(socket_name, &unix_addr, &unix_addr_len)); | 123 MakeUnixAddrForPath(socket_path.value(), &unix_addr, &unix_addr_len)); |
| 128 if (!fd.is_valid()) | 124 if (!fd.is_valid()) |
| 129 return false; | 125 return false; |
| 130 | 126 |
| 131 if (HANDLE_EINTR(connect(fd.get(), reinterpret_cast<sockaddr*>(&unix_addr), | 127 if (HANDLE_EINTR(connect(fd.get(), reinterpret_cast<sockaddr*>(&unix_addr), |
| 132 unix_addr_len)) < 0) { | 128 unix_addr_len)) < 0) { |
| 133 PLOG(ERROR) << "connect " << socket_path.value(); | 129 PLOG(ERROR) << "connect " << socket_path.value(); |
| 134 return false; | 130 return false; |
| 135 } | 131 } |
| 136 | 132 |
| 137 *client_socket = fd.release(); | 133 *client_socket = fd.release(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 // It's safe to keep listening on |server_listen_fd| even if the attempt to | 189 // It's safe to keep listening on |server_listen_fd| even if the attempt to |
| 194 // set O_NONBLOCK failed on the client fd. | 190 // set O_NONBLOCK failed on the client fd. |
| 195 return true; | 191 return true; |
| 196 } | 192 } |
| 197 | 193 |
| 198 *server_socket = accept_fd.release(); | 194 *server_socket = accept_fd.release(); |
| 199 return true; | 195 return true; |
| 200 } | 196 } |
| 201 | 197 |
| 202 } // namespace IPC | 198 } // namespace IPC |
| OLD | NEW |