OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 static const int kSavedStringLimit = 128; | 23 static const int kSavedStringLimit = 128; |
24 | 24 |
25 static void SaveStringToStack(char *dst, | 25 static void SaveStringToStack(char *dst, |
26 const std::string &src, | 26 const std::string &src, |
27 size_t dst_size) { | 27 size_t dst_size) { |
28 strncpy(dst, src.c_str(), dst_size - 1); | 28 strncpy(dst, src.c_str(), dst_size - 1); |
29 dst[dst_size - 1] = '\0'; | 29 dst[dst_size - 1] = '\0'; |
30 } | 30 } |
31 | 31 |
32 AutoDetectProxy::AutoDetectProxy(const std::string& user_agent) | 32 AutoDetectProxy::AutoDetectProxy(const std::string& user_agent) |
33 : agent_(user_agent), resolver_(NULL), socket_(NULL), next_(0) { | 33 : agent_(user_agent), resolver_(nullptr), socket_(nullptr), next_(0) {} |
34 } | |
35 | 34 |
36 bool AutoDetectProxy::GetProxyForUrl(const char* agent, | 35 bool AutoDetectProxy::GetProxyForUrl(const char* agent, |
37 const char* url, | 36 const char* url, |
38 rtc::ProxyInfo* proxy) { | 37 rtc::ProxyInfo* proxy) { |
39 return GetProxySettingsForUrl(agent, url, proxy, true); | 38 return GetProxySettingsForUrl(agent, url, proxy, true); |
40 } | 39 } |
41 | 40 |
42 AutoDetectProxy::~AutoDetectProxy() { | 41 AutoDetectProxy::~AutoDetectProxy() { |
43 if (resolver_) { | 42 if (resolver_) { |
44 resolver_->Destroy(false); | 43 resolver_->Destroy(false); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 if (error == 0) { | 136 if (error == 0) { |
138 LOG(LS_VERBOSE) << "Resolved " << proxy_.address << " to " | 137 LOG(LS_VERBOSE) << "Resolved " << proxy_.address << " to " |
139 << resolver_->address(); | 138 << resolver_->address(); |
140 proxy_.address = resolver_->address(); | 139 proxy_.address = resolver_->address(); |
141 if (!DoConnect()) { | 140 if (!DoConnect()) { |
142 Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TIMEOUT); | 141 Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TIMEOUT); |
143 } | 142 } |
144 } else { | 143 } else { |
145 LOG(LS_INFO) << "Failed to resolve " << resolver_->address(); | 144 LOG(LS_INFO) << "Failed to resolve " << resolver_->address(); |
146 resolver_->Destroy(false); | 145 resolver_->Destroy(false); |
147 resolver_ = NULL; | 146 resolver_ = nullptr; |
148 proxy_.address = SocketAddress(); | 147 proxy_.address = SocketAddress(); |
149 Thread::Current()->Post(RTC_FROM_HERE, this, MSG_UNRESOLVABLE); | 148 Thread::Current()->Post(RTC_FROM_HERE, this, MSG_UNRESOLVABLE); |
150 } | 149 } |
151 } | 150 } |
152 | 151 |
153 void AutoDetectProxy::Next() { | 152 void AutoDetectProxy::Next() { |
154 if (TEST_ORDER[next_] >= PROXY_UNKNOWN) { | 153 if (TEST_ORDER[next_] >= PROXY_UNKNOWN) { |
155 Complete(PROXY_UNKNOWN); | 154 Complete(PROXY_UNKNOWN); |
156 return; | 155 return; |
157 } | 156 } |
158 | 157 |
159 LOG(LS_VERBOSE) << "AutoDetectProxy connecting to " | 158 LOG(LS_VERBOSE) << "AutoDetectProxy connecting to " |
160 << proxy_.address.ToSensitiveString(); | 159 << proxy_.address.ToSensitiveString(); |
161 | 160 |
162 if (socket_) { | 161 if (socket_) { |
163 Thread::Current()->Clear(this, MSG_TIMEOUT); | 162 Thread::Current()->Clear(this, MSG_TIMEOUT); |
164 Thread::Current()->Clear(this, MSG_UNRESOLVABLE); | 163 Thread::Current()->Clear(this, MSG_UNRESOLVABLE); |
165 socket_->Close(); | 164 socket_->Close(); |
166 Thread::Current()->Dispose(socket_); | 165 Thread::Current()->Dispose(socket_); |
167 socket_ = NULL; | 166 socket_ = nullptr; |
168 } | 167 } |
169 int timeout = 2000; | 168 int timeout = 2000; |
170 if (proxy_.address.IsUnresolvedIP()) { | 169 if (proxy_.address.IsUnresolvedIP()) { |
171 // Launch an asyncresolver. This thread will spin waiting for it. | 170 // Launch an asyncresolver. This thread will spin waiting for it. |
172 timeout += 2000; | 171 timeout += 2000; |
173 if (!resolver_) { | 172 if (!resolver_) { |
174 resolver_ = new AsyncResolver(); | 173 resolver_ = new AsyncResolver(); |
175 } | 174 } |
176 resolver_->SignalDone.connect(this, &AutoDetectProxy::OnResolveResult); | 175 resolver_->SignalDone.connect(this, &AutoDetectProxy::OnResolveResult); |
177 resolver_->Start(proxy_.address); | 176 resolver_->Start(proxy_.address); |
178 } else { | 177 } else { |
179 if (!DoConnect()) { | 178 if (!DoConnect()) { |
180 Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TIMEOUT); | 179 Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TIMEOUT); |
181 return; | 180 return; |
182 } | 181 } |
183 } | 182 } |
184 Thread::Current()->PostDelayed(RTC_FROM_HERE, timeout, this, MSG_TIMEOUT); | 183 Thread::Current()->PostDelayed(RTC_FROM_HERE, timeout, this, MSG_TIMEOUT); |
185 } | 184 } |
186 | 185 |
187 bool AutoDetectProxy::DoConnect() { | 186 bool AutoDetectProxy::DoConnect() { |
188 if (resolver_) { | 187 if (resolver_) { |
189 resolver_->Destroy(false); | 188 resolver_->Destroy(false); |
190 resolver_ = NULL; | 189 resolver_ = nullptr; |
191 } | 190 } |
192 socket_ = | 191 socket_ = |
193 Thread::Current()->socketserver()->CreateAsyncSocket( | 192 Thread::Current()->socketserver()->CreateAsyncSocket( |
194 proxy_.address.family(), SOCK_STREAM); | 193 proxy_.address.family(), SOCK_STREAM); |
195 if (!socket_) { | 194 if (!socket_) { |
196 LOG(LS_VERBOSE) << "Unable to create socket for " << proxy_.address; | 195 LOG(LS_VERBOSE) << "Unable to create socket for " << proxy_.address; |
197 return false; | 196 return false; |
198 } | 197 } |
199 socket_->SignalConnectEvent.connect(this, &AutoDetectProxy::OnConnectEvent); | 198 socket_->SignalConnectEvent.connect(this, &AutoDetectProxy::OnConnectEvent); |
200 socket_->SignalReadEvent.connect(this, &AutoDetectProxy::OnReadEvent); | 199 socket_->SignalReadEvent.connect(this, &AutoDetectProxy::OnReadEvent); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 Next(); | 292 Next(); |
294 } | 293 } |
295 | 294 |
296 void AutoDetectProxy::OnCloseEvent(AsyncSocket * socket, int error) { | 295 void AutoDetectProxy::OnCloseEvent(AsyncSocket * socket, int error) { |
297 LOG(LS_VERBOSE) << "AutoDetectProxy closed with error: " << error; | 296 LOG(LS_VERBOSE) << "AutoDetectProxy closed with error: " << error; |
298 ++next_; | 297 ++next_; |
299 Next(); | 298 Next(); |
300 } | 299 } |
301 | 300 |
302 } // namespace rtc | 301 } // namespace rtc |
OLD | NEW |