| 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/shell/domain_socket/unix_domain_server_socket_posix.h" | 5 #include "shell/domain_socket/unix_domain_server_socket_posix.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
| 9 #include <sys/un.h> | 9 #include <sys/un.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "mojo/shell/domain_socket/completion_callback.h" | 13 #include "shell/domain_socket/completion_callback.h" |
| 14 #include "mojo/shell/domain_socket/net_errors.h" | 14 #include "shell/domain_socket/net_errors.h" |
| 15 #include "mojo/shell/domain_socket/socket_descriptor.h" | 15 #include "shell/domain_socket/socket_descriptor.h" |
| 16 #include "mojo/shell/domain_socket/socket_libevent.h" | 16 #include "shell/domain_socket/socket_libevent.h" |
| 17 #include "mojo/shell/domain_socket/unix_domain_client_socket_posix.h" | 17 #include "shell/domain_socket/unix_domain_client_socket_posix.h" |
| 18 | 18 |
| 19 namespace mojo { | 19 namespace mojo { |
| 20 namespace shell { | 20 namespace shell { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // Intended for use as SetterCallbacks in Accept() helper methods. | 24 // Intended for use as SetterCallbacks in Accept() helper methods. |
| 25 void SetSocketDescriptor(SocketDescriptor* socket, | 25 void SetSocketDescriptor(SocketDescriptor* socket, |
| 26 scoped_ptr<SocketLibevent> accepted_socket) { | 26 scoped_ptr<SocketLibevent> accepted_socket) { |
| 27 *socket = accepted_socket->ReleaseConnectedSocket(); | 27 *socket = accepted_socket->ReleaseConnectedSocket(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 51 credentials->user_id = user_cred.uid; | 51 credentials->user_id = user_cred.uid; |
| 52 credentials->group_id = user_cred.gid; | 52 credentials->group_id = user_cred.gid; |
| 53 return true; | 53 return true; |
| 54 } | 54 } |
| 55 | 55 |
| 56 int UnixDomainServerSocket::ListenWithPath(const std::string& unix_domain_path, | 56 int UnixDomainServerSocket::ListenWithPath(const std::string& unix_domain_path, |
| 57 int backlog) { | 57 int backlog) { |
| 58 DCHECK(!listen_socket_); | 58 DCHECK(!listen_socket_); |
| 59 | 59 |
| 60 SockaddrStorage address; | 60 SockaddrStorage address; |
| 61 if (!UnixDomainClientSocket::FillAddress( | 61 if (!UnixDomainClientSocket::FillAddress(unix_domain_path, |
| 62 unix_domain_path, use_abstract_namespace_, &address)) { | 62 use_abstract_namespace_, &address)) { |
| 63 return net::ERR_ADDRESS_INVALID; | 63 return net::ERR_ADDRESS_INVALID; |
| 64 } | 64 } |
| 65 | 65 |
| 66 scoped_ptr<SocketLibevent> socket(new SocketLibevent); | 66 scoped_ptr<SocketLibevent> socket(new SocketLibevent); |
| 67 int rv = socket->Open(AF_UNIX); | 67 int rv = socket->Open(AF_UNIX); |
| 68 DCHECK_NE(net::ERR_IO_PENDING, rv); | 68 DCHECK_NE(net::ERR_IO_PENDING, rv); |
| 69 if (rv != net::OK) | 69 if (rv != net::OK) |
| 70 return rv; | 70 return rv; |
| 71 | 71 |
| 72 rv = socket->Bind(address); | 72 rv = socket->Bind(address); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 99 const CompletionCallback& callback) { | 99 const CompletionCallback& callback) { |
| 100 DCHECK(!setter_callback.is_null()); | 100 DCHECK(!setter_callback.is_null()); |
| 101 DCHECK(!callback.is_null()); | 101 DCHECK(!callback.is_null()); |
| 102 DCHECK(listen_socket_); | 102 DCHECK(listen_socket_); |
| 103 DCHECK(!accept_socket_); | 103 DCHECK(!accept_socket_); |
| 104 | 104 |
| 105 while (true) { | 105 while (true) { |
| 106 int rv = listen_socket_->Accept( | 106 int rv = listen_socket_->Accept( |
| 107 &accept_socket_, | 107 &accept_socket_, |
| 108 base::Bind(&UnixDomainServerSocket::AcceptCompleted, | 108 base::Bind(&UnixDomainServerSocket::AcceptCompleted, |
| 109 base::Unretained(this), | 109 base::Unretained(this), setter_callback, callback)); |
| 110 setter_callback, | |
| 111 callback)); | |
| 112 if (rv != net::OK) | 110 if (rv != net::OK) |
| 113 return rv; | 111 return rv; |
| 114 if (AuthenticateAndGetStreamSocket(setter_callback)) | 112 if (AuthenticateAndGetStreamSocket(setter_callback)) |
| 115 return net::OK; | 113 return net::OK; |
| 116 // Accept another socket because authentication error should be transparent | 114 // Accept another socket because authentication error should be transparent |
| 117 // to the caller. | 115 // to the caller. |
| 118 } | 116 } |
| 119 } | 117 } |
| 120 | 118 |
| 121 void UnixDomainServerSocket::AcceptCompleted( | 119 void UnixDomainServerSocket::AcceptCompleted( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 149 accept_socket_.reset(); | 147 accept_socket_.reset(); |
| 150 return false; | 148 return false; |
| 151 } | 149 } |
| 152 | 150 |
| 153 setter_callback.Run(accept_socket_.Pass()); | 151 setter_callback.Run(accept_socket_.Pass()); |
| 154 return true; | 152 return true; |
| 155 } | 153 } |
| 156 | 154 |
| 157 } // namespace shell | 155 } // namespace shell |
| 158 } // namespace mojo | 156 } // namespace mojo |
| OLD | NEW |