Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / net / tools / quic / test_tools / server_thread.h
blobb017440506a8aaf4c2ca99014d0ec271b4b7d47e
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.
5 #ifndef NET_TOOLS_QUIC_TEST_TOOLS_SERVER_THREAD_H_
6 #define NET_TOOLS_QUIC_TEST_TOOLS_SERVER_THREAD_H_
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"
13 namespace net {
14 namespace tools {
15 namespace test {
17 // Simple wrapper class to run QuicServer in a dedicated thread.
18 class ServerThread : public base::SimpleThread {
19 public:
20 ServerThread(QuicServer* server,
21 bool is_secure,
22 const IPEndPoint& address,
23 bool strike_register_no_startup_period);
25 ~ServerThread() override;
27 // Prepares the server, but does not start accepting connections. Useful for
28 // injecting mocks.
29 void Initialize();
31 // Runs the event loop. Will initialize if necessary.
32 void Run() override;
34 // Waits for the handshake to be confirmed for the first session created.
35 void WaitForCryptoHandshakeConfirmed();
37 // Pauses execution of the server until Resume() is called. May only be
38 // called once.
39 void Pause();
41 // Resumes execution of the server after Pause() has been called. May only
42 // be called once.
43 void Resume();
45 // Stops the server from executing and shuts it down, destroying all
46 // server objects.
47 void Quit();
49 // Returns the underlying server. Care must be taken to avoid data races
50 // when accessing the server. It is always safe to access the server
51 // after calling Pause() and before calling Resume().
52 QuicServer* server() { return server_.get(); }
54 // Returns the port that the server is listening on.
55 int GetPort();
57 private:
58 void MaybeNotifyOfHandshakeConfirmation();
60 base::WaitableEvent confirmed_; // Notified when the first handshake is
61 // confirmed.
62 base::WaitableEvent pause_; // Notified when the server should pause.
63 base::WaitableEvent paused_; // Notitied when the server has paused
64 base::WaitableEvent resume_; // Notified when the server should resume.
65 base::WaitableEvent quit_; // Notified when the server should quit.
67 scoped_ptr<QuicServer> server_;
68 IPEndPoint address_;
69 base::Lock port_lock_;
70 int port_;
72 bool initialized_;
74 DISALLOW_COPY_AND_ASSIGN(ServerThread);
77 } // namespace test
78 } // namespace tools
79 } // namespace net
81 #endif // NET_TOOLS_QUIC_TEST_TOOLS_SERVER_THREAD_H_