| 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 "extensions/browser/api/socket/tcp_socket.h" | 5 #include "extensions/browser/api/socket/tcp_socket.h" |
| 6 | 6 |
| 7 #include "extensions/browser/api/api_resource.h" | 7 #include "extensions/browser/api/api_resource.h" |
| 8 #include "net/base/address_list.h" | 8 #include "net/base/address_list.h" |
| 9 #include "net/base/ip_endpoint.h" | 9 #include "net/base/ip_endpoint.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 int port, | 189 int port, |
| 190 int backlog, | 190 int backlog, |
| 191 std::string* error_msg) { | 191 std::string* error_msg) { |
| 192 if (socket_mode_ == CLIENT) { | 192 if (socket_mode_ == CLIENT) { |
| 193 *error_msg = kTCPSocketTypeInvalidError; | 193 *error_msg = kTCPSocketTypeInvalidError; |
| 194 return net::ERR_NOT_IMPLEMENTED; | 194 return net::ERR_NOT_IMPLEMENTED; |
| 195 } | 195 } |
| 196 DCHECK(!socket_.get()); | 196 DCHECK(!socket_.get()); |
| 197 socket_mode_ = SERVER; | 197 socket_mode_ = SERVER; |
| 198 | 198 |
| 199 scoped_ptr<net::IPEndPoint> bind_address(new net::IPEndPoint()); | |
| 200 if (!StringAndPortToIPEndPoint(address, port, bind_address.get())) | |
| 201 return net::ERR_INVALID_ARGUMENT; | |
| 202 | |
| 203 if (!server_socket_.get()) { | 199 if (!server_socket_.get()) { |
| 204 server_socket_.reset(new net::TCPServerSocket(NULL, net::NetLog::Source())); | 200 server_socket_.reset(new net::TCPServerSocket(NULL, net::NetLog::Source())); |
| 205 } | 201 } |
| 206 int result = server_socket_->Listen(*bind_address, backlog); | 202 int result = server_socket_->ListenWithAddressAndPort(address, port, backlog); |
| 207 if (result) | 203 if (result) |
| 208 *error_msg = kSocketListenError; | 204 *error_msg = kSocketListenError; |
| 209 return result; | 205 return result; |
| 210 } | 206 } |
| 211 | 207 |
| 212 void TCPSocket::Accept(const AcceptCompletionCallback& callback) { | 208 void TCPSocket::Accept(const AcceptCompletionCallback& callback) { |
| 213 if (socket_mode_ != SERVER || !server_socket_.get()) { | 209 if (socket_mode_ != SERVER || !server_socket_.get()) { |
| 214 callback.Run(net::ERR_FAILED, NULL); | 210 callback.Run(net::ERR_FAILED, NULL); |
| 215 return; | 211 return; |
| 216 } | 212 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 | 316 |
| 321 bool ResumableTCPSocket::IsPersistent() const { return persistent(); } | 317 bool ResumableTCPSocket::IsPersistent() const { return persistent(); } |
| 322 | 318 |
| 323 ResumableTCPServerSocket::ResumableTCPServerSocket( | 319 ResumableTCPServerSocket::ResumableTCPServerSocket( |
| 324 const std::string& owner_extension_id) | 320 const std::string& owner_extension_id) |
| 325 : TCPSocket(owner_extension_id), persistent_(false), paused_(false) {} | 321 : TCPSocket(owner_extension_id), persistent_(false), paused_(false) {} |
| 326 | 322 |
| 327 bool ResumableTCPServerSocket::IsPersistent() const { return persistent(); } | 323 bool ResumableTCPServerSocket::IsPersistent() const { return persistent(); } |
| 328 | 324 |
| 329 } // namespace extensions | 325 } // namespace extensions |
| OLD | NEW |