| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_socket_posix.h" | 5 #include "net/socket/unix_domain_socket_posix.h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include <errno.h> | 10 #include <errno.h> |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 // static | 50 // static |
| 51 UnixDomainSocket::AuthCallback NoAuthentication() { | 51 UnixDomainSocket::AuthCallback NoAuthentication() { |
| 52 return base::Bind(NoAuthenticationCallback); | 52 return base::Bind(NoAuthenticationCallback); |
| 53 } | 53 } |
| 54 | 54 |
| 55 // static | 55 // static |
| 56 UnixDomainSocket* UnixDomainSocket::CreateAndListenInternal( | 56 UnixDomainSocket* UnixDomainSocket::CreateAndListenInternal( |
| 57 const std::string& path, | 57 const std::string& path, |
| 58 const std::string& fallback_path, |
| 58 StreamListenSocket::Delegate* del, | 59 StreamListenSocket::Delegate* del, |
| 59 const AuthCallback& auth_callback, | 60 const AuthCallback& auth_callback, |
| 60 bool use_abstract_namespace) { | 61 bool use_abstract_namespace) { |
| 61 SocketDescriptor s = CreateAndBind(path, use_abstract_namespace); | 62 SocketDescriptor s = CreateAndBind(path, use_abstract_namespace); |
| 63 if (s == kInvalidSocket && !fallback_path.empty()) |
| 64 s = CreateAndBind(fallback_path, use_abstract_namespace); |
| 62 if (s == kInvalidSocket) | 65 if (s == kInvalidSocket) |
| 63 return NULL; | 66 return NULL; |
| 64 UnixDomainSocket* sock = new UnixDomainSocket(s, del, auth_callback); | 67 UnixDomainSocket* sock = new UnixDomainSocket(s, del, auth_callback); |
| 65 sock->Listen(); | 68 sock->Listen(); |
| 66 return sock; | 69 return sock; |
| 67 } | 70 } |
| 68 | 71 |
| 69 // static | 72 // static |
| 70 scoped_refptr<UnixDomainSocket> UnixDomainSocket::CreateAndListen( | 73 scoped_refptr<UnixDomainSocket> UnixDomainSocket::CreateAndListen( |
| 71 const std::string& path, | 74 const std::string& path, |
| 72 StreamListenSocket::Delegate* del, | 75 StreamListenSocket::Delegate* del, |
| 73 const AuthCallback& auth_callback) { | 76 const AuthCallback& auth_callback) { |
| 74 return CreateAndListenInternal(path, del, auth_callback, false); | 77 return CreateAndListenInternal(path, "", del, auth_callback, false); |
| 75 } | 78 } |
| 76 | 79 |
| 77 #if defined(SOCKET_ABSTRACT_NAMESPACE_SUPPORTED) | 80 #if defined(SOCKET_ABSTRACT_NAMESPACE_SUPPORTED) |
| 78 // static | 81 // static |
| 79 scoped_refptr<UnixDomainSocket> | 82 scoped_refptr<UnixDomainSocket> |
| 80 UnixDomainSocket::CreateAndListenWithAbstractNamespace( | 83 UnixDomainSocket::CreateAndListenWithAbstractNamespace( |
| 81 const std::string& path, | 84 const std::string& path, |
| 85 const std::string& fallback_path, |
| 82 StreamListenSocket::Delegate* del, | 86 StreamListenSocket::Delegate* del, |
| 83 const AuthCallback& auth_callback) { | 87 const AuthCallback& auth_callback) { |
| 84 return make_scoped_refptr( | 88 return make_scoped_refptr( |
| 85 CreateAndListenInternal(path, del, auth_callback, true)); | 89 CreateAndListenInternal(path, fallback_path, del, auth_callback, true)); |
| 86 } | 90 } |
| 87 #endif | 91 #endif |
| 88 | 92 |
| 89 UnixDomainSocket::UnixDomainSocket( | 93 UnixDomainSocket::UnixDomainSocket( |
| 90 SocketDescriptor s, | 94 SocketDescriptor s, |
| 91 StreamListenSocket::Delegate* del, | 95 StreamListenSocket::Delegate* del, |
| 92 const AuthCallback& auth_callback) | 96 const AuthCallback& auth_callback) |
| 93 : StreamListenSocket(s, del), | 97 : StreamListenSocket(s, del), |
| 94 auth_callback_(auth_callback) {} | 98 auth_callback_(auth_callback) {} |
| 95 | 99 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 UnixDomainSocketFactory::UnixDomainSocketFactory( | 157 UnixDomainSocketFactory::UnixDomainSocketFactory( |
| 154 const std::string& path, | 158 const std::string& path, |
| 155 const UnixDomainSocket::AuthCallback& auth_callback) | 159 const UnixDomainSocket::AuthCallback& auth_callback) |
| 156 : path_(path), | 160 : path_(path), |
| 157 auth_callback_(auth_callback) {} | 161 auth_callback_(auth_callback) {} |
| 158 | 162 |
| 159 UnixDomainSocketFactory::~UnixDomainSocketFactory() {} | 163 UnixDomainSocketFactory::~UnixDomainSocketFactory() {} |
| 160 | 164 |
| 161 scoped_refptr<StreamListenSocket> UnixDomainSocketFactory::CreateAndListen( | 165 scoped_refptr<StreamListenSocket> UnixDomainSocketFactory::CreateAndListen( |
| 162 StreamListenSocket::Delegate* delegate) const { | 166 StreamListenSocket::Delegate* delegate) const { |
| 163 return UnixDomainSocket::CreateAndListen(path_, delegate, auth_callback_); | 167 return UnixDomainSocket::CreateAndListen( |
| 168 path_, delegate, auth_callback_); |
| 164 } | 169 } |
| 165 | 170 |
| 166 #if defined(SOCKET_ABSTRACT_NAMESPACE_SUPPORTED) | 171 #if defined(SOCKET_ABSTRACT_NAMESPACE_SUPPORTED) |
| 167 | 172 |
| 168 UnixDomainSocketWithAbstractNamespaceFactory:: | 173 UnixDomainSocketWithAbstractNamespaceFactory:: |
| 169 UnixDomainSocketWithAbstractNamespaceFactory( | 174 UnixDomainSocketWithAbstractNamespaceFactory( |
| 170 const std::string& path, | 175 const std::string& path, |
| 176 const std::string& fallback_path, |
| 171 const UnixDomainSocket::AuthCallback& auth_callback) | 177 const UnixDomainSocket::AuthCallback& auth_callback) |
| 172 : UnixDomainSocketFactory(path, auth_callback) {} | 178 : UnixDomainSocketFactory(path, auth_callback), |
| 179 fallback_path_(fallback_path) {} |
| 173 | 180 |
| 174 UnixDomainSocketWithAbstractNamespaceFactory:: | 181 UnixDomainSocketWithAbstractNamespaceFactory:: |
| 175 ~UnixDomainSocketWithAbstractNamespaceFactory() {} | 182 ~UnixDomainSocketWithAbstractNamespaceFactory() {} |
| 176 | 183 |
| 177 scoped_refptr<StreamListenSocket> | 184 scoped_refptr<StreamListenSocket> |
| 178 UnixDomainSocketWithAbstractNamespaceFactory::CreateAndListen( | 185 UnixDomainSocketWithAbstractNamespaceFactory::CreateAndListen( |
| 179 StreamListenSocket::Delegate* delegate) const { | 186 StreamListenSocket::Delegate* delegate) const { |
| 180 return UnixDomainSocket::CreateAndListenWithAbstractNamespace( | 187 return UnixDomainSocket::CreateAndListenWithAbstractNamespace( |
| 181 path_, delegate, auth_callback_); | 188 path_, fallback_path_, delegate, auth_callback_); |
| 182 } | 189 } |
| 183 | 190 |
| 184 #endif | 191 #endif |
| 185 | 192 |
| 186 } // namespace net | 193 } // namespace net |
| OLD | NEW |