OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "jingle/notifier/communicator/login.h" | 7 #include "jingle/notifier/communicator/login.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 307 } |
308 | 308 |
309 void Login::CheckConnection() { | 309 void Login::CheckConnection() { |
310 // We don't check the connection if we're using ChromeAsyncSocket, | 310 // We don't check the connection if we're using ChromeAsyncSocket, |
311 // as this code requires a libjingle thread to be running. This | 311 // as this code requires a libjingle thread to be running. This |
312 // code will go away in a future cleanup CL, anyway. | 312 // code will go away in a future cleanup CL, anyway. |
313 if (!use_chrome_async_socket_) { | 313 if (!use_chrome_async_socket_) { |
314 LOG(INFO) << "Checking connection"; | 314 LOG(INFO) << "Checking connection"; |
315 talk_base::PhysicalSocketServer physical; | 315 talk_base::PhysicalSocketServer physical; |
316 scoped_ptr<talk_base::Socket> socket(physical.CreateSocket(SOCK_STREAM)); | 316 scoped_ptr<talk_base::Socket> socket(physical.CreateSocket(SOCK_STREAM)); |
317 bool alive = | 317 talk_base::SocketAddress addr("talk.google.com", 5222); |
318 !socket->Connect(talk_base::SocketAddress("talk.google.com", 5222)); | 318 // Resolve synchronously to avoid weirdness with libjingle's async |
| 319 // DNS resolver. |
| 320 bool alive = addr.ResolveIP() && (socket->Connect(addr) == 0); |
319 LOG(INFO) << "Network is " << (alive ? "alive" : "not alive"); | 321 LOG(INFO) << "Network is " << (alive ? "alive" : "not alive"); |
320 if (alive) { | 322 if (alive) { |
321 // Our connection is up. If we have a disconnect timer going, | 323 // Our connection is up. If we have a disconnect timer going, |
322 // stop it so we don't disconnect. | 324 // stop it so we don't disconnect. |
323 disconnect_timer_.Stop(); | 325 disconnect_timer_.Stop(); |
324 } else { | 326 } else { |
325 // Our network connection is down. Start the disconnect timer if | 327 // Our network connection is down. Start the disconnect timer if |
326 // it's not already going. Don't disconnect immediately to avoid | 328 // it's not already going. Don't disconnect immediately to avoid |
327 // constant connection/disconnection due to flaky network | 329 // constant connection/disconnection due to flaky network |
328 // interfaces. | 330 // interfaces. |
(...skipping 14 matching lines...) Expand all Loading... |
343 | 345 |
344 if (single_attempt_) { | 346 if (single_attempt_) { |
345 single_attempt_->Abort(); | 347 single_attempt_->Abort(); |
346 single_attempt_ = NULL; | 348 single_attempt_ = NULL; |
347 } | 349 } |
348 | 350 |
349 StartConnection(); | 351 StartConnection(); |
350 } | 352 } |
351 | 353 |
352 } // namespace notifier | 354 } // namespace notifier |
OLD | NEW |