Land Recent QUIC Changes
[chromium-blink-merge.git] / net / tools / quic / test_tools / server_thread.h
blob94737842f89c286dab7fe9c69543344d07d9aa82
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_SERVER_THREAD_H_
6 #define NET_TOOLS_QUIC_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 server in a thread.
18 class ServerThread : public base::SimpleThread {
19 public:
20 ServerThread(IPEndPoint address,
21 const QuicConfig& config,
22 const QuicVersionVector& supported_versions,
23 bool strike_register_no_startup_period,
24 uint32 server_initial_flow_control_receive_window);
26 virtual ~ServerThread();
28 // Prepares the server, but does not start accepting connections. Useful for
29 // injecting mocks.
30 void Initialize();
32 // Runs the event loop. Will initialize if necessary.
33 virtual void Run() OVERRIDE;
35 // Waits for the handshake to be confirmed for the first session created.
36 void WaitForCryptoHandshakeConfirmed();
38 // Pauses execution of the server until Resume() is called. May only be
39 // called once.
40 void Pause();
42 // Resumes execution of the server after Pause() has been called. May only
43 // be called once.
44 void Resume();
46 // Stops the server from executing and shuts it down, destroying all
47 // server objects.
48 void Quit();
50 // Returns the underlying server. Care must be taken to avoid data races
51 // when accessing the server. It is always safe to access the server
52 // after calling Pause() and before calling Resume().
53 QuicServer* server() { return &server_; }
55 // Returns the port that the server is listening on.
56 int GetPort();
58 private:
59 void MaybeNotifyOfHandshakeConfirmation();
61 base::WaitableEvent confirmed_; // Notified when the first handshake is
62 // confirmed.
63 base::WaitableEvent pause_; // Notified when the server should pause.
64 base::WaitableEvent paused_; // Notitied when the server has paused
65 base::WaitableEvent resume_; // Notified when the server should resume.
66 base::WaitableEvent quit_; // Notified when the server should quit.
68 tools::QuicServer server_;
69 IPEndPoint address_;
70 base::Lock port_lock_;
71 int port_;
73 bool initialized_;
75 DISALLOW_COPY_AND_ASSIGN(ServerThread);
78 } // namespace test
79 } // namespace tools
80 } // namespace net
82 #endif // NET_TOOLS_QUIC_SERVER_THREAD_H_