Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: net/socket/tcp_pinger.h

Issue 155020: Speed up net_unittests by ~20s by manipulating tcp_pinger timeouts. (Closed)
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 10 tries, each with a timeout of 1000ms, 44 // Default is 40 tries, each with a timeout of 250ms,
45 // for a total max timeout of 10 seconds. 45 // for a total max timeout of 10 seconds.
46 return Ping(base::TimeDelta::FromMilliseconds(1000), 10); 46 return Ping(base::TimeDelta::FromMilliseconds(250), 40);
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
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_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698