| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef NET_SOCKET_TCP_PINGER_H_ | 5 #ifndef NET_SOCKET_TCP_PINGER_H_ |
| 6 #define NET_SOCKET_TCP_PINGER_H_ | 6 #define NET_SOCKET_TCP_PINGER_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 base::Thread::Options options; | 34 base::Thread::Options options; |
| 35 options.message_loop_type = MessageLoop::TYPE_IO; | 35 options.message_loop_type = MessageLoop::TYPE_IO; |
| 36 io_thread_.StartWithOptions(options); | 36 io_thread_.StartWithOptions(options); |
| 37 } | 37 } |
| 38 | 38 |
| 39 ~TCPPinger() { | 39 ~TCPPinger() { |
| 40 io_thread_.message_loop()->ReleaseSoon(FROM_HERE, worker_); | 40 io_thread_.message_loop()->ReleaseSoon(FROM_HERE, worker_); |
| 41 } | 41 } |
| 42 | 42 |
| 43 int Ping() { | 43 int Ping() { |
| 44 // Default is 40 tries, each with a timeout of 250ms, | 44 // Default is 10 tries, each with a timeout of 1000ms, |
| 45 // for a total max timeout of 10 seconds. | 45 // for a total max timeout of 10 seconds. |
| 46 return Ping(base::TimeDelta::FromMilliseconds(250), 40); | 46 return Ping(base::TimeDelta::FromMilliseconds(1000), 10); |
| 47 } | 47 } |
| 48 | 48 |
| 49 int Ping(base::TimeDelta tryTimeout, int nTries) { | 49 int Ping(base::TimeDelta tryTimeout, int nTries) { |
| 50 int err = ERR_IO_PENDING; | 50 int err = ERR_IO_PENDING; |
| 51 // Post a request to do the connect on that thread. | 51 // Post a request to do the connect on that thread. |
| 52 for (int i = 0; i < nTries; i++) { | 52 for (int i = 0; i < nTries; i++) { |
| 53 io_thread_.message_loop()->PostTask(FROM_HERE, | 53 io_thread_.message_loop()->PostTask(FROM_HERE, |
| 54 NewRunnableMethod(worker_, | 54 NewRunnableMethod(worker_, |
| 55 &net::TCPPinger::Worker::DoConnect)); | 55 &net::TCPPinger::Worker::DoConnect)); |
| 56 // Timeout here in case remote host offline | 56 // Timeout here in case remote host offline |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 base::Thread io_thread_; | 125 base::Thread io_thread_; |
| 126 Worker* worker_; | 126 Worker* worker_; |
| 127 DISALLOW_COPY_AND_ASSIGN(TCPPinger); | 127 DISALLOW_COPY_AND_ASSIGN(TCPPinger); |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 } // namespace net | 130 } // namespace net |
| 131 | 131 |
| 132 #endif // NET_SOCKET_TCP_PINGER_H_ | 132 #endif // NET_SOCKET_TCP_PINGER_H_ |
| OLD | NEW |