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_client_socket_posix.h" | 5 #include "net/socket/unix_domain_client_socket_posix.h" |
6 | 6 |
7 #include <sys/socket.h> | 7 #include <sys/socket.h> |
8 #include <sys/un.h> | 8 #include <sys/un.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/posix/eintr_wrapper.h" | 11 #include "base/posix/eintr_wrapper.h" |
12 #include "net/base/ip_endpoint.h" | 12 #include "net/base/ip_endpoint.h" |
13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
14 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
15 #include "net/socket/socket_libevent.h" | 15 #include "net/socket/socket_posix.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 | 18 |
19 UnixDomainClientSocket::UnixDomainClientSocket(const std::string& socket_path, | 19 UnixDomainClientSocket::UnixDomainClientSocket(const std::string& socket_path, |
20 bool use_abstract_namespace) | 20 bool use_abstract_namespace) |
21 : socket_path_(socket_path), | 21 : socket_path_(socket_path), |
22 use_abstract_namespace_(use_abstract_namespace) { | 22 use_abstract_namespace_(use_abstract_namespace) { |
23 } | 23 } |
24 | 24 |
25 UnixDomainClientSocket::UnixDomainClientSocket( | 25 UnixDomainClientSocket::UnixDomainClientSocket(scoped_ptr<SocketPosix> socket) |
26 scoped_ptr<SocketLibevent> socket) | 26 : use_abstract_namespace_(false), socket_(socket.Pass()) {} |
27 : use_abstract_namespace_(false), | |
28 socket_(socket.Pass()) { | |
29 } | |
30 | 27 |
31 UnixDomainClientSocket::~UnixDomainClientSocket() { | 28 UnixDomainClientSocket::~UnixDomainClientSocket() { |
32 Disconnect(); | 29 Disconnect(); |
33 } | 30 } |
34 | 31 |
35 // static | 32 // static |
36 bool UnixDomainClientSocket::FillAddress(const std::string& socket_path, | 33 bool UnixDomainClientSocket::FillAddress(const std::string& socket_path, |
37 bool use_abstract_namespace, | 34 bool use_abstract_namespace, |
38 SockaddrStorage* address) { | 35 SockaddrStorage* address) { |
39 struct sockaddr_un* socket_addr = | 36 struct sockaddr_un* socket_addr = |
(...skipping 30 matching lines...) Expand all Loading... |
70 int UnixDomainClientSocket::Connect(const CompletionCallback& callback) { | 67 int UnixDomainClientSocket::Connect(const CompletionCallback& callback) { |
71 DCHECK(!socket_); | 68 DCHECK(!socket_); |
72 | 69 |
73 if (socket_path_.empty()) | 70 if (socket_path_.empty()) |
74 return ERR_ADDRESS_INVALID; | 71 return ERR_ADDRESS_INVALID; |
75 | 72 |
76 SockaddrStorage address; | 73 SockaddrStorage address; |
77 if (!FillAddress(socket_path_, use_abstract_namespace_, &address)) | 74 if (!FillAddress(socket_path_, use_abstract_namespace_, &address)) |
78 return ERR_ADDRESS_INVALID; | 75 return ERR_ADDRESS_INVALID; |
79 | 76 |
80 socket_.reset(new SocketLibevent); | 77 socket_.reset(new SocketPosix); |
81 int rv = socket_->Open(AF_UNIX); | 78 int rv = socket_->Open(AF_UNIX); |
82 DCHECK_NE(ERR_IO_PENDING, rv); | 79 DCHECK_NE(ERR_IO_PENDING, rv); |
83 if (rv != OK) | 80 if (rv != OK) |
84 return rv; | 81 return rv; |
85 | 82 |
86 return socket_->Connect(address, callback); | 83 return socket_->Connect(address, callback); |
87 } | 84 } |
88 | 85 |
89 void UnixDomainClientSocket::Disconnect() { | 86 void UnixDomainClientSocket::Disconnect() { |
90 socket_.reset(); | 87 socket_.reset(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 SocketDescriptor UnixDomainClientSocket::ReleaseConnectedSocket() { | 177 SocketDescriptor UnixDomainClientSocket::ReleaseConnectedSocket() { |
181 DCHECK(socket_); | 178 DCHECK(socket_); |
182 DCHECK(socket_->IsConnected()); | 179 DCHECK(socket_->IsConnected()); |
183 | 180 |
184 SocketDescriptor socket_fd = socket_->ReleaseConnectedSocket(); | 181 SocketDescriptor socket_fd = socket_->ReleaseConnectedSocket(); |
185 socket_.reset(); | 182 socket_.reset(); |
186 return socket_fd; | 183 return socket_fd; |
187 } | 184 } |
188 | 185 |
189 } // namespace net | 186 } // namespace net |
OLD | NEW |