OLD | NEW |
| (Empty) |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_TOOLS_QUIC_SERVER_THREAD_H_ | |
6 #define NET_TOOLS_QUIC_SERVER_THREAD_H_ | |
7 | |
8 #include "base/threading/simple_thread.h" | |
9 #include "net/base/ip_endpoint.h" | |
10 #include "net/quic/quic_config.h" | |
11 #include "net/tools/quic/quic_server.h" | |
12 | |
13 namespace net { | |
14 namespace tools { | |
15 namespace test { | |
16 | |
17 // Simple wrapper class to run server in a thread. | |
18 class ServerThread : public base::SimpleThread { | |
19 public: | |
20 ServerThread(QuicServer* server, | |
21 IPEndPoint address, | |
22 bool strike_register_no_startup_period); | |
23 | |
24 ~ServerThread() override; | |
25 | |
26 // Prepares the server, but does not start accepting connections. Useful for | |
27 // injecting mocks. | |
28 void Initialize(); | |
29 | |
30 // Runs the event loop. Will initialize if necessary. | |
31 void Run() override; | |
32 | |
33 // Waits for the handshake to be confirmed for the first session created. | |
34 void WaitForCryptoHandshakeConfirmed(); | |
35 | |
36 // Pauses execution of the server until Resume() is called. May only be | |
37 // called once. | |
38 void Pause(); | |
39 | |
40 // Resumes execution of the server after Pause() has been called. May only | |
41 // be called once. | |
42 void Resume(); | |
43 | |
44 // Stops the server from executing and shuts it down, destroying all | |
45 // server objects. | |
46 void Quit(); | |
47 | |
48 // Returns the underlying server. Care must be taken to avoid data races | |
49 // when accessing the server. It is always safe to access the server | |
50 // after calling Pause() and before calling Resume(). | |
51 QuicServer* server() { return server_.get(); } | |
52 | |
53 // Returns the port that the server is listening on. | |
54 int GetPort(); | |
55 | |
56 private: | |
57 void MaybeNotifyOfHandshakeConfirmation(); | |
58 | |
59 base::WaitableEvent confirmed_; // Notified when the first handshake is | |
60 // confirmed. | |
61 base::WaitableEvent pause_; // Notified when the server should pause. | |
62 base::WaitableEvent paused_; // Notitied when the server has paused | |
63 base::WaitableEvent resume_; // Notified when the server should resume. | |
64 base::WaitableEvent quit_; // Notified when the server should quit. | |
65 | |
66 scoped_ptr<QuicServer> server_; | |
67 IPEndPoint address_; | |
68 base::Lock port_lock_; | |
69 int port_; | |
70 | |
71 bool initialized_; | |
72 | |
73 DISALLOW_COPY_AND_ASSIGN(ServerThread); | |
74 }; | |
75 | |
76 } // namespace test | |
77 } // namespace tools | |
78 } // namespace net | |
79 | |
80 #endif // NET_TOOLS_QUIC_SERVER_THREAD_H_ | |
OLD | NEW |