| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 | 81 |
| 82 #if defined(SOCKET_ABSTRACT_NAMESPACE_SUPPORTED) | 82 #if defined(SOCKET_ABSTRACT_NAMESPACE_SUPPORTED) |
| 83 // static | 83 // static |
| 84 scoped_ptr<UnixDomainSocket> | 84 scoped_ptr<UnixDomainSocket> |
| 85 UnixDomainSocket::CreateAndListenWithAbstractNamespace( | 85 UnixDomainSocket::CreateAndListenWithAbstractNamespace( |
| 86 const std::string& path, | 86 const std::string& path, |
| 87 const std::string& fallback_path, | 87 const std::string& fallback_path, |
| 88 StreamListenSocket::Delegate* del, | 88 StreamListenSocket::Delegate* del, |
| 89 const AuthCallback& auth_callback) { | 89 const AuthCallback& auth_callback) { |
| 90 return | 90 return CreateAndListenInternal(path, fallback_path, del, auth_callback, true); |
| 91 CreateAndListenInternal(path, fallback_path, del, auth_callback, true); | |
| 92 } | 91 } |
| 93 #endif | 92 #endif |
| 94 | 93 |
| 95 UnixDomainSocket::UnixDomainSocket( | 94 UnixDomainSocket::UnixDomainSocket(SocketDescriptor s, |
| 96 SocketDescriptor s, | 95 StreamListenSocket::Delegate* del, |
| 97 StreamListenSocket::Delegate* del, | 96 const AuthCallback& auth_callback) |
| 98 const AuthCallback& auth_callback) | 97 : StreamListenSocket(s, del), auth_callback_(auth_callback) { |
| 99 : StreamListenSocket(s, del), | 98 } |
| 100 auth_callback_(auth_callback) {} | |
| 101 | 99 |
| 102 UnixDomainSocket::~UnixDomainSocket() {} | 100 UnixDomainSocket::~UnixDomainSocket() { |
| 101 } |
| 103 | 102 |
| 104 // static | 103 // static |
| 105 SocketDescriptor UnixDomainSocket::CreateAndBind(const std::string& path, | 104 SocketDescriptor UnixDomainSocket::CreateAndBind(const std::string& path, |
| 106 bool use_abstract_namespace) { | 105 bool use_abstract_namespace) { |
| 107 sockaddr_un addr; | 106 sockaddr_un addr; |
| 108 static const size_t kPathMax = sizeof(addr.sun_path); | 107 static const size_t kPathMax = sizeof(addr.sun_path); |
| 109 if (use_abstract_namespace + path.size() + 1 /* '\0' */ > kPathMax) | 108 if (use_abstract_namespace + path.size() + 1 /* '\0' */ > kPathMax) |
| 110 return kInvalidSocket; | 109 return kInvalidSocket; |
| 111 const SocketDescriptor s = CreatePlatformSocket(PF_UNIX, SOCK_STREAM, 0); | 110 const SocketDescriptor s = CreatePlatformSocket(PF_UNIX, SOCK_STREAM, 0); |
| 112 if (s == kInvalidSocket) | 111 if (s == kInvalidSocket) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 scoped_ptr<UnixDomainSocket> sock( | 151 scoped_ptr<UnixDomainSocket> sock( |
| 153 new UnixDomainSocket(conn, socket_delegate_, auth_callback_)); | 152 new UnixDomainSocket(conn, socket_delegate_, auth_callback_)); |
| 154 // It's up to the delegate to AddRef if it wants to keep it around. | 153 // It's up to the delegate to AddRef if it wants to keep it around. |
| 155 sock->WatchSocket(WAITING_READ); | 154 sock->WatchSocket(WAITING_READ); |
| 156 socket_delegate_->DidAccept(this, sock.PassAs<StreamListenSocket>()); | 155 socket_delegate_->DidAccept(this, sock.PassAs<StreamListenSocket>()); |
| 157 } | 156 } |
| 158 | 157 |
| 159 UnixDomainSocketFactory::UnixDomainSocketFactory( | 158 UnixDomainSocketFactory::UnixDomainSocketFactory( |
| 160 const std::string& path, | 159 const std::string& path, |
| 161 const UnixDomainSocket::AuthCallback& auth_callback) | 160 const UnixDomainSocket::AuthCallback& auth_callback) |
| 162 : path_(path), | 161 : path_(path), auth_callback_(auth_callback) { |
| 163 auth_callback_(auth_callback) {} | 162 } |
| 164 | 163 |
| 165 UnixDomainSocketFactory::~UnixDomainSocketFactory() {} | 164 UnixDomainSocketFactory::~UnixDomainSocketFactory() { |
| 165 } |
| 166 | 166 |
| 167 scoped_ptr<StreamListenSocket> UnixDomainSocketFactory::CreateAndListen( | 167 scoped_ptr<StreamListenSocket> UnixDomainSocketFactory::CreateAndListen( |
| 168 StreamListenSocket::Delegate* delegate) const { | 168 StreamListenSocket::Delegate* delegate) const { |
| 169 return UnixDomainSocket::CreateAndListen( | 169 return UnixDomainSocket::CreateAndListen(path_, delegate, auth_callback_) |
| 170 path_, delegate, auth_callback_).PassAs<StreamListenSocket>(); | 170 .PassAs<StreamListenSocket>(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 #if defined(SOCKET_ABSTRACT_NAMESPACE_SUPPORTED) | 173 #if defined(SOCKET_ABSTRACT_NAMESPACE_SUPPORTED) |
| 174 | 174 |
| 175 UnixDomainSocketWithAbstractNamespaceFactory:: | 175 UnixDomainSocketWithAbstractNamespaceFactory:: |
| 176 UnixDomainSocketWithAbstractNamespaceFactory( | 176 UnixDomainSocketWithAbstractNamespaceFactory( |
| 177 const std::string& path, | 177 const std::string& path, |
| 178 const std::string& fallback_path, | 178 const std::string& fallback_path, |
| 179 const UnixDomainSocket::AuthCallback& auth_callback) | 179 const UnixDomainSocket::AuthCallback& auth_callback) |
| 180 : UnixDomainSocketFactory(path, auth_callback), | 180 : UnixDomainSocketFactory(path, auth_callback), |
| 181 fallback_path_(fallback_path) {} | 181 fallback_path_(fallback_path) { |
| 182 } |
| 182 | 183 |
| 183 UnixDomainSocketWithAbstractNamespaceFactory:: | 184 UnixDomainSocketWithAbstractNamespaceFactory:: |
| 184 ~UnixDomainSocketWithAbstractNamespaceFactory() {} | 185 ~UnixDomainSocketWithAbstractNamespaceFactory() { |
| 186 } |
| 185 | 187 |
| 186 scoped_ptr<StreamListenSocket> | 188 scoped_ptr<StreamListenSocket> |
| 187 UnixDomainSocketWithAbstractNamespaceFactory::CreateAndListen( | 189 UnixDomainSocketWithAbstractNamespaceFactory::CreateAndListen( |
| 188 StreamListenSocket::Delegate* delegate) const { | 190 StreamListenSocket::Delegate* delegate) const { |
| 189 return UnixDomainSocket::CreateAndListenWithAbstractNamespace( | 191 return UnixDomainSocket::CreateAndListenWithAbstractNamespace( |
| 190 path_, fallback_path_, delegate, auth_callback_) | 192 path_, fallback_path_, delegate, auth_callback_) |
| 191 .PassAs<StreamListenSocket>(); | 193 .PassAs<StreamListenSocket>(); |
| 192 } | 194 } |
| 193 | 195 |
| 194 #endif | 196 #endif |
| 195 | 197 |
| 196 } // namespace net | 198 } // namespace net |
| OLD | NEW |