Windows should animate when they are about to get docked at screen edges.
[chromium-blink-merge.git] / net / tools / quic / quic_dispatcher.h
blobbbf8d9b49417ffa102f93e3296a37997439b079e
1 // Copyright (c) 2012 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 // A server side dispatcher which dispatches a given client's data to their
6 // stream.
8 #ifndef NET_TOOLS_QUIC_QUIC_DISPATCHER_H_
9 #define NET_TOOLS_QUIC_QUIC_DISPATCHER_H_
11 #include <list>
13 #include "base/containers/hash_tables.h"
14 #include "net/base/ip_endpoint.h"
15 #include "net/quic/blocked_list.h"
16 #include "net/quic/quic_blocked_writer_interface.h"
17 #include "net/quic/quic_protocol.h"
18 #include "net/tools/flip_server/epoll_server.h"
19 #include "net/tools/quic/quic_packet_writer.h"
20 #include "net/tools/quic/quic_server_session.h"
21 #include "net/tools/quic/quic_time_wait_list_manager.h"
23 #if defined(COMPILER_GCC)
24 namespace BASE_HASH_NAMESPACE {
25 template<>
26 struct hash<net::QuicBlockedWriterInterface*> {
27 std::size_t operator()(
28 const net::QuicBlockedWriterInterface* ptr) const {
29 return hash<size_t>()(reinterpret_cast<size_t>(ptr));
33 #endif
35 namespace net {
37 class EpollServer;
38 class QuicConfig;
39 class QuicCryptoServerConfig;
40 class QuicSession;
42 namespace tools {
44 namespace test {
45 class QuicDispatcherPeer;
46 } // namespace test
48 class DeleteSessionsAlarm;
49 class QuicDispatcher : public QuicPacketWriter, public QuicSessionOwner {
50 public:
51 typedef BlockedList<QuicBlockedWriterInterface*> WriteBlockedList;
53 // Due to the way delete_sessions_closure_ is registered, the Dispatcher
54 // must live until epoll_server Shutdown.
55 QuicDispatcher(const QuicConfig& config,
56 const QuicCryptoServerConfig& crypto_config,
57 int fd,
58 EpollServer* epoll_server);
59 virtual ~QuicDispatcher();
61 // QuicPacketWriter
62 virtual int WritePacket(const char* buffer, size_t buf_len,
63 const IPAddressNumber& self_address,
64 const IPEndPoint& peer_address,
65 QuicBlockedWriterInterface* writer,
66 int* error) OVERRIDE;
68 virtual void ProcessPacket(const IPEndPoint& server_address,
69 const IPEndPoint& client_address,
70 QuicGuid guid,
71 const QuicEncryptedPacket& packet);
73 // Called when the underyling connection becomes writable to allow
74 // queued writes to happen.
76 // Returns true if more writes are possible, false otherwise.
77 virtual bool OnCanWrite();
79 // Sends ConnectionClose frames to all connected clients.
80 void Shutdown();
82 // Ensure that the closed connection is cleaned up asynchronously.
83 virtual void OnConnectionClose(QuicGuid guid, QuicErrorCode error) OVERRIDE;
85 int fd() { return fd_; }
86 void set_fd(int fd) { fd_ = fd; }
88 typedef base::hash_map<QuicGuid, QuicSession*> SessionMap;
90 virtual QuicSession* CreateQuicSession(
91 QuicGuid guid,
92 const IPEndPoint& client_address,
93 int fd,
94 EpollServer* epoll_server);
96 // Deletes all sessions on the closed session list and clears the list.
97 void DeleteSessions();
99 const SessionMap& session_map() const { return session_map_; }
101 WriteBlockedList* write_blocked_list() { return &write_blocked_list_; }
103 protected:
104 const QuicConfig& config_;
105 const QuicCryptoServerConfig& crypto_config_;
107 QuicTimeWaitListManager* time_wait_list_manager() {
108 return time_wait_list_manager_.get();
111 private:
112 friend class net::tools::test::QuicDispatcherPeer;
114 // Removes the session from the session map and write blocked list, and
115 // adds the GUID to the time-wait list.
116 void CleanUpSession(SessionMap::iterator it);
118 // The list of connections waiting to write.
119 WriteBlockedList write_blocked_list_;
121 SessionMap session_map_;
123 // Entity that manages guids in time wait state.
124 scoped_ptr<QuicTimeWaitListManager> time_wait_list_manager_;
126 // An alarm which deletes closed sessions.
127 scoped_ptr<DeleteSessionsAlarm> delete_sessions_alarm_;
129 // The list of closed but not-yet-deleted sessions.
130 std::list<QuicSession*> closed_session_list_;
132 EpollServer* epoll_server_; // Owned by the server.
134 // The connection for client-server communication
135 int fd_;
137 // True if the session is write blocked due to the socket returning EAGAIN.
138 // False if we have gotten a call to OnCanWrite after the last failed write.
139 bool write_blocked_;
141 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher);
144 } // namespace tools
145 } // namespace net
147 #endif // NET_TOOLS_QUIC_QUIC_DISPATCHER_H_