OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_SPDY_SPDY_SESSION_H_ | 5 #ifndef NET_SPDY_SPDY_SESSION_H_ |
6 #define NET_SPDY_SPDY_SESSION_H_ | 6 #define NET_SPDY_SPDY_SESSION_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <deque> | 9 #include <deque> |
10 #include <list> | 10 #include <list> |
11 #include <map> | 11 #include <map> |
12 #include <queue> | 12 #include <queue> |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/memory/linked_ptr.h" | 16 #include "base/memory/linked_ptr.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/task.h" | 18 #include "base/task.h" |
19 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
20 #include "net/base/load_states.h" | 20 #include "net/base/load_states.h" |
21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
22 #include "net/base/net_log.h" | 22 #include "net/base/net_log.h" |
23 #include "net/base/request_priority.h" | 23 #include "net/base/request_priority.h" |
24 #include "net/base/ssl_config_service.h" | 24 #include "net/base/ssl_config_service.h" |
25 #include "net/base/upload_data_stream.h" | 25 #include "net/base/upload_data_stream.h" |
26 #include "net/socket/client_socket.h" | 26 #include "net/socket/client_socket.h" |
27 #include "net/socket/client_socket_handle.h" | 27 #include "net/socket/client_socket_handle.h" |
| 28 #include "net/socket/sctp_client_socket_pool.h" |
28 #include "net/socket/tcp_client_socket_pool.h" | 29 #include "net/socket/tcp_client_socket_pool.h" |
29 #include "net/spdy/spdy_framer.h" | 30 #include "net/spdy/spdy_framer.h" |
30 #include "net/spdy/spdy_io_buffer.h" | 31 #include "net/spdy/spdy_io_buffer.h" |
31 #include "net/spdy/spdy_protocol.h" | 32 #include "net/spdy/spdy_protocol.h" |
32 #include "net/spdy/spdy_session_pool.h" | 33 #include "net/spdy/spdy_session_pool.h" |
33 | 34 |
34 namespace net { | 35 namespace net { |
35 | 36 |
36 // This is somewhat arbitrary and not really fixed, but it will always work | 37 // This is somewhat arbitrary and not really fixed, but it will always work |
37 // reasonably with ethernet. Chop the world into 2-packet chunks. This is | 38 // reasonably with ethernet. Chop the world into 2-packet chunks. This is |
38 // somewhat arbitrary, but is reasonably small and ensures that we elicit | 39 // somewhat arbitrary, but is reasonably small and ensures that we elicit |
39 // ACKs quickly from TCP (because TCP tries to only ACK every other packet). | 40 // ACKs quickly from TCP (because TCP tries to only ACK every other packet). |
| 41 // TODO(jtl): Replace kMss with kMss_TCP = 1430 and kMss_SCTP = 1452 and set |
| 42 // MaxSpdyFrameChunkSize appropriately, based on which transport protocol we're |
| 43 // using. |
40 const int kMss = 1430; | 44 const int kMss = 1430; |
41 const int kMaxSpdyFrameChunkSize = (2 * kMss) - spdy::SpdyFrame::size(); | 45 const int kMaxSpdyFrameChunkSize = (2 * kMss) - spdy::SpdyFrame::size(); |
42 | 46 |
43 class BoundNetLog; | 47 class BoundNetLog; |
44 class SpdySettingsStorage; | 48 class SpdySettingsStorage; |
45 class SpdyStream; | 49 class SpdyStream; |
46 class SSLInfo; | 50 class SSLInfo; |
47 | 51 |
48 class SpdySession : public base::RefCounted<SpdySession>, | 52 class SpdySession : public base::RefCounted<SpdySession>, |
49 public spdy::SpdyFramerVisitorInterface { | 53 public spdy::SpdyFramerVisitorInterface { |
50 public: | 54 public: |
51 // Create a new SpdySession. | 55 // Create a new SpdySession. |
52 // |host_port_proxy_pair| is the host/port that this session connects to, and | 56 // |host_port_proxy_pair| is the host/port that this session connects to, and |
53 // the proxy configuration settings that it's using. | 57 // the proxy configuration settings that it's using. |
54 // |spdy_session_pool| is the SpdySessionPool that owns us. Its lifetime must | 58 // |spdy_session_pool| is the SpdySessionPool that owns us. Its lifetime must |
55 // strictly be greater than |this|. | 59 // strictly be greater than |this|. |
56 // |session| is the HttpNetworkSession. |net_log| is the NetLog that we log | 60 // |session| is the HttpNetworkSession. |net_log| is the NetLog that we log |
57 // network events to. | 61 // network events to. |
58 SpdySession(const HostPortProxyPair& host_port_proxy_pair, | 62 SpdySession(const HostPortProxyPair& host_port_proxy_pair, |
59 SpdySessionPool* spdy_session_pool, | 63 SpdySessionPool* spdy_session_pool, |
60 SpdySettingsStorage* spdy_settings, | 64 SpdySettingsStorage* spdy_settings, |
61 NetLog* net_log); | 65 NetLog* net_log); |
| 66 typedef void (SpdySession::*OnTransportConnect)(int result); |
| 67 SpdySession(const HostPortProxyPair& host_port_proxy_pair, |
| 68 SpdySessionPool* spdy_session_pool, |
| 69 SpdySettingsStorage* spdy_settings, |
| 70 OnTransportConnect on_transport_connect, |
| 71 NetLog* net_log); |
62 | 72 |
63 const HostPortPair& host_port_pair() const { | 73 const HostPortPair& host_port_pair() const { |
64 return host_port_proxy_pair_.first; | 74 return host_port_proxy_pair_.first; |
65 } | 75 } |
66 const HostPortProxyPair& host_port_proxy_pair() const { | 76 const HostPortProxyPair& host_port_proxy_pair() const { |
67 return host_port_proxy_pair_; | 77 return host_port_proxy_pair_; |
68 } | 78 } |
69 | 79 |
70 // Get a pushed stream for a given |url|. | 80 // Get a pushed stream for a given |url|. |
71 // If the server initiates a stream, it might already exist for a given path. | 81 // If the server initiates a stream, it might already exist for a given path. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 bool IsReused() const { | 189 bool IsReused() const { |
180 return frames_received_ > 0; | 190 return frames_received_ > 0; |
181 } | 191 } |
182 | 192 |
183 // Returns true if the underlying transport socket ever had any reads or | 193 // Returns true if the underlying transport socket ever had any reads or |
184 // writes. | 194 // writes. |
185 bool WasEverUsed() const { | 195 bool WasEverUsed() const { |
186 return connection_->socket()->WasEverUsed(); | 196 return connection_->socket()->WasEverUsed(); |
187 } | 197 } |
188 | 198 |
| 199 // Returns true if the underling socket's transport protocol is SCTP. |
| 200 bool using_sctp() { |
| 201 if (connection_.get()->is_initialized()) |
| 202 return connection_.get()->socket()->protocol() == |
| 203 IPPROTO_SCTP ? true : false; |
| 204 else |
| 205 // TODO(jtl): return sctp_enabled() here? |
| 206 return false; |
| 207 } |
| 208 |
| 209 // Returns true if the underlying socket's transport protocol is SCTP and SPDY |
| 210 // control frames are being sent on SCTP stream 0. |
| 211 bool using_sctp_control_stream() { |
| 212 if (connection_.get()->is_initialized()) |
| 213 return connection_.get()->socket()->using_sctp_control_stream(); |
| 214 else |
| 215 // TODO(jtl): return sctp_enabled() here? |
| 216 return false; |
| 217 } |
| 218 |
| 219 // Maps a SPDY stream number to an SCTP stream ID. |
| 220 uint16 MapSpdyToSctp(uint32 stream_id) { |
| 221 return connection_->socket()->MapSpdyToSctp(stream_id); |
| 222 } |
| 223 |
189 void set_spdy_session_pool(SpdySessionPool* pool) { | 224 void set_spdy_session_pool(SpdySessionPool* pool) { |
190 spdy_session_pool_ = NULL; | 225 spdy_session_pool_ = NULL; |
191 } | 226 } |
192 | 227 |
193 // Access to the number of active and pending streams. These are primarily | 228 // Access to the number of active and pending streams. These are primarily |
194 // available for testing and diagnostics. | 229 // available for testing and diagnostics. |
195 size_t num_active_streams() const { return active_streams_.size(); } | 230 size_t num_active_streams() const { return active_streams_.size(); } |
196 size_t num_unclaimed_pushed_streams() const { | 231 size_t num_unclaimed_pushed_streams() const { |
197 return unclaimed_pushed_streams_.size(); | 232 return unclaimed_pushed_streams_.size(); |
198 } | 233 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 // Returns OK on success, or an error on failure. | 320 // Returns OK on success, or an error on failure. |
286 net::Error ReadSocket(); | 321 net::Error ReadSocket(); |
287 | 322 |
288 // Write current data to the socket. | 323 // Write current data to the socket. |
289 void WriteSocketLater(); | 324 void WriteSocketLater(); |
290 void WriteSocket(); | 325 void WriteSocket(); |
291 | 326 |
292 // Get a new stream id. | 327 // Get a new stream id. |
293 int GetNewStreamId(); | 328 int GetNewStreamId(); |
294 | 329 |
| 330 // Get the SCTP stream ID for this SPDY frame. |
| 331 uint16 GetSctpStreamID(const spdy::SpdyFrame& frame); |
| 332 |
295 // Queue a frame for sending. | 333 // Queue a frame for sending. |
296 // |frame| is the frame to send. | 334 // |frame| is the frame to send. |
297 // |priority| is the priority for insertion into the queue. | 335 // |priority| is the priority for insertion into the queue. |
298 // |stream| is the stream which this IO is associated with (or NULL). | 336 // |stream| is the stream which this IO is associated with (or NULL). |
299 void QueueFrame(spdy::SpdyFrame* frame, spdy::SpdyPriority priority, | 337 void QueueFrame(spdy::SpdyFrame* frame, spdy::SpdyPriority priority, |
300 SpdyStream* stream); | 338 SpdyStream* stream); |
301 | 339 |
302 // Track active streams in the active stream list. | 340 // Track active streams in the active stream list. |
303 void ActivateStream(SpdyStream* stream); | 341 void ActivateStream(SpdyStream* stream); |
304 void DeleteStream(spdy::SpdyStreamId id, int status); | 342 void DeleteStream(spdy::SpdyStreamId id, int status); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 const spdy::SpdyControlFlags flags_; | 497 const spdy::SpdyControlFlags flags_; |
460 const spdy::SpdyStreamId id_; | 498 const spdy::SpdyStreamId id_; |
461 const spdy::SpdyStreamId associated_stream_; | 499 const spdy::SpdyStreamId associated_stream_; |
462 | 500 |
463 DISALLOW_COPY_AND_ASSIGN(NetLogSpdySynParameter); | 501 DISALLOW_COPY_AND_ASSIGN(NetLogSpdySynParameter); |
464 }; | 502 }; |
465 | 503 |
466 } // namespace net | 504 } // namespace net |
467 | 505 |
468 #endif // NET_SPDY_SPDY_SESSION_H_ | 506 #endif // NET_SPDY_SPDY_SESSION_H_ |
OLD | NEW |