| 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 "net/socket/unix_domain_server_socket_posix.h" | 5 #include "net/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 "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "net/socket/socket_libevent.h" | 14 #include "net/socket/socket_posix.h" |
| 15 #include "net/socket/unix_domain_client_socket_posix.h" | 15 #include "net/socket/unix_domain_client_socket_posix.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // Intended for use as SetterCallbacks in Accept() helper methods. | 21 // Intended for use as SetterCallbacks in Accept() helper methods. |
| 22 void SetStreamSocket(scoped_ptr<StreamSocket>* socket, | 22 void SetStreamSocket(scoped_ptr<StreamSocket>* socket, |
| 23 scoped_ptr<SocketLibevent> accepted_socket) { | 23 scoped_ptr<SocketPosix> accepted_socket) { |
| 24 socket->reset(new UnixDomainClientSocket(accepted_socket.Pass())); | 24 socket->reset(new UnixDomainClientSocket(accepted_socket.Pass())); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void SetSocketDescriptor(SocketDescriptor* socket, | 27 void SetSocketDescriptor(SocketDescriptor* socket, |
| 28 scoped_ptr<SocketLibevent> accepted_socket) { | 28 scoped_ptr<SocketPosix> accepted_socket) { |
| 29 *socket = accepted_socket->ReleaseConnectedSocket(); | 29 *socket = accepted_socket->ReleaseConnectedSocket(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 } // anonymous namespace | 32 } // anonymous namespace |
| 33 | 33 |
| 34 UnixDomainServerSocket::UnixDomainServerSocket( | 34 UnixDomainServerSocket::UnixDomainServerSocket( |
| 35 const AuthCallback& auth_callback, | 35 const AuthCallback& auth_callback, |
| 36 bool use_abstract_namespace) | 36 bool use_abstract_namespace) |
| 37 : auth_callback_(auth_callback), | 37 : auth_callback_(auth_callback), |
| 38 use_abstract_namespace_(use_abstract_namespace) { | 38 use_abstract_namespace_(use_abstract_namespace) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 int backlog) { | 71 int backlog) { |
| 72 DCHECK(!listen_socket_); | 72 DCHECK(!listen_socket_); |
| 73 | 73 |
| 74 SockaddrStorage address; | 74 SockaddrStorage address; |
| 75 if (!UnixDomainClientSocket::FillAddress(unix_domain_path, | 75 if (!UnixDomainClientSocket::FillAddress(unix_domain_path, |
| 76 use_abstract_namespace_, | 76 use_abstract_namespace_, |
| 77 &address)) { | 77 &address)) { |
| 78 return ERR_ADDRESS_INVALID; | 78 return ERR_ADDRESS_INVALID; |
| 79 } | 79 } |
| 80 | 80 |
| 81 scoped_ptr<SocketLibevent> socket(new SocketLibevent); | 81 scoped_ptr<SocketPosix> socket(new SocketPosix); |
| 82 int rv = socket->Open(AF_UNIX); | 82 int rv = socket->Open(AF_UNIX); |
| 83 DCHECK_NE(ERR_IO_PENDING, rv); | 83 DCHECK_NE(ERR_IO_PENDING, rv); |
| 84 if (rv != OK) | 84 if (rv != OK) |
| 85 return rv; | 85 return rv; |
| 86 | 86 |
| 87 rv = socket->Bind(address); | 87 rv = socket->Bind(address); |
| 88 DCHECK_NE(ERR_IO_PENDING, rv); | 88 DCHECK_NE(ERR_IO_PENDING, rv); |
| 89 if (rv != OK) { | 89 if (rv != OK) { |
| 90 PLOG(ERROR) | 90 PLOG(ERROR) |
| 91 << "Could not bind unix domain socket to " << unix_domain_path | 91 << "Could not bind unix domain socket to " << unix_domain_path |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 !auth_callback_.Run(credentials)) { | 180 !auth_callback_.Run(credentials)) { |
| 181 accept_socket_.reset(); | 181 accept_socket_.reset(); |
| 182 return false; | 182 return false; |
| 183 } | 183 } |
| 184 | 184 |
| 185 setter_callback.Run(accept_socket_.Pass()); | 185 setter_callback.Run(accept_socket_.Pass()); |
| 186 return true; | 186 return true; |
| 187 } | 187 } |
| 188 | 188 |
| 189 } // namespace net | 189 } // namespace net |
| OLD | NEW |