| 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/ipc_channel_factory.h" | 5 #include "ipc/ipc_channel_factory.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "ipc/unix_domain_socket_util.h" | 9 #include "ipc/unix_domain_socket_util.h" |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // Create the socket. | 26 // Create the socket. |
| 27 return CreateServerUnixDomainSocket(path_, &listen_fd_); | 27 return CreateServerUnixDomainSocket(path_, &listen_fd_); |
| 28 } | 28 } |
| 29 | 29 |
| 30 bool ChannelFactory::Listen() { | 30 bool ChannelFactory::Listen() { |
| 31 if (listen_fd_ < 0) | 31 if (listen_fd_ < 0) |
| 32 return false; | 32 return false; |
| 33 | 33 |
| 34 // Watch the fd for connections, and turn any connections into | 34 // Watch the fd for connections, and turn any connections into |
| 35 // active sockets. | 35 // active sockets. |
| 36 MessageLoopForIO::current()->WatchFileDescriptor( | 36 base::MessageLoopForIO::current()->WatchFileDescriptor( |
| 37 listen_fd_, | 37 listen_fd_, |
| 38 true, | 38 true, |
| 39 MessageLoopForIO::WATCH_READ, | 39 base::MessageLoopForIO::WATCH_READ, |
| 40 &server_listen_connection_watcher_, | 40 &server_listen_connection_watcher_, |
| 41 this); | 41 this); |
| 42 return true; | 42 return true; |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Called by libevent when we can read from the fd without blocking. | 45 // Called by libevent when we can read from the fd without blocking. |
| 46 void ChannelFactory::OnFileCanReadWithoutBlocking(int fd) { | 46 void ChannelFactory::OnFileCanReadWithoutBlocking(int fd) { |
| 47 DCHECK(fd == listen_fd_); | 47 DCHECK(fd == listen_fd_); |
| 48 int new_fd = -1; | 48 int new_fd = -1; |
| 49 if (!ServerAcceptConnection(listen_fd_, &new_fd)) { | 49 if (!ServerAcceptConnection(listen_fd_, &new_fd)) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 80 PLOG(ERROR) << "close"; | 80 PLOG(ERROR) << "close"; |
| 81 listen_fd_ = -1; | 81 listen_fd_ = -1; |
| 82 if (unlink(path_.value().c_str()) < 0) | 82 if (unlink(path_.value().c_str()) < 0) |
| 83 PLOG(ERROR) << "unlink"; | 83 PLOG(ERROR) << "unlink"; |
| 84 | 84 |
| 85 // Unregister libevent for the listening socket and close it. | 85 // Unregister libevent for the listening socket and close it. |
| 86 server_listen_connection_watcher_.StopWatchingFileDescriptor(); | 86 server_listen_connection_watcher_.StopWatchingFileDescriptor(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 } // namespace IPC | 89 } // namespace IPC |
| OLD | NEW |