OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/base/client_socket_handle.h" | 5 #include "net/base/client_socket_handle.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "net/base/client_socket.h" | 9 #include "net/base/client_socket.h" |
10 #include "net/base/client_socket_pool.h" | 10 #include "net/base/client_socket_pool.h" |
11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 ClientSocketHandle::ClientSocketHandle(ClientSocketPool* pool) | 15 ClientSocketHandle::ClientSocketHandle(ClientSocketPool* pool) |
16 : pool_(pool), | 16 : pool_(pool), |
17 socket_(NULL), | 17 socket_(NULL), |
18 is_reused_(false), | 18 is_reused_(false), |
19 ALLOW_THIS_IN_INITIALIZER_LIST( | 19 ALLOW_THIS_IN_INITIALIZER_LIST( |
20 callback_(this, &ClientSocketHandle::OnIOComplete)) {} | 20 callback_(this, &ClientSocketHandle::OnIOComplete)) {} |
21 | 21 |
22 ClientSocketHandle::~ClientSocketHandle() { | 22 ClientSocketHandle::~ClientSocketHandle() { |
23 Reset(); | 23 Reset(); |
24 } | 24 } |
25 | 25 |
26 int ClientSocketHandle::Init(const std::string& group_name, | 26 int ClientSocketHandle::Init(const std::string& group_name, |
27 const std::string& host, | 27 const HostResolver::RequestInfo& resolve_info, |
28 int port, | |
29 int priority, | 28 int priority, |
30 CompletionCallback* callback) { | 29 CompletionCallback* callback) { |
31 ResetInternal(true); | 30 ResetInternal(true); |
32 group_name_ = group_name; | 31 group_name_ = group_name; |
33 user_callback_ = callback; | 32 user_callback_ = callback; |
34 return pool_->RequestSocket( | 33 return pool_->RequestSocket( |
35 group_name, host, port, priority, this, &callback_); | 34 group_name, resolve_info, priority, this, &callback_); |
36 } | 35 } |
37 | 36 |
38 void ClientSocketHandle::Reset() { | 37 void ClientSocketHandle::Reset() { |
39 ResetInternal(true); | 38 ResetInternal(true); |
40 } | 39 } |
41 | 40 |
42 void ClientSocketHandle::ResetInternal(bool cancel) { | 41 void ClientSocketHandle::ResetInternal(bool cancel) { |
43 if (group_name_.empty()) // Was Init called? | 42 if (group_name_.empty()) // Was Init called? |
44 return; | 43 return; |
45 if (socket_.get()) { | 44 if (socket_.get()) { |
(...skipping 19 matching lines...) Expand all Loading... |
65 void ClientSocketHandle::OnIOComplete(int result) { | 64 void ClientSocketHandle::OnIOComplete(int result) { |
66 CHECK(ERR_IO_PENDING != result); | 65 CHECK(ERR_IO_PENDING != result); |
67 CompletionCallback* callback = user_callback_; | 66 CompletionCallback* callback = user_callback_; |
68 user_callback_ = NULL; | 67 user_callback_ = NULL; |
69 if (result != OK) | 68 if (result != OK) |
70 ResetInternal(false); // The request failed, so there's nothing to cancel. | 69 ResetInternal(false); // The request failed, so there's nothing to cancel. |
71 callback->Run(result); | 70 callback->Run(result); |
72 } | 71 } |
73 | 72 |
74 } // namespace net | 73 } // namespace net |
OLD | NEW |