OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "net/quic/quic_client_session.h" | 5 #include "net/quic/quic_client_session.h" |
6 | 6 |
7 #include "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 | 10 |
11 QuicClientSession::QuicClientSession(QuicConnection* connection) | 11 QuicClientSession::QuicClientSession(QuicConnection* connection) |
12 : QuicSession(connection, false), | 12 : QuicSession(connection, false), |
13 crypto_stream_(this) { | 13 crypto_stream_(this) { |
14 } | 14 } |
15 | 15 |
16 QuicClientSession::~QuicClientSession() { | 16 QuicClientSession::~QuicClientSession() { |
| 17 STLDeleteValues(&streams_); |
17 } | 18 } |
18 | 19 |
19 QuicReliableClientStream* QuicClientSession::CreateOutgoingReliableStream() { | 20 QuicReliableClientStream* QuicClientSession::CreateOutgoingReliableStream() { |
20 if (!crypto_stream_.handshake_complete()) { | 21 if (!crypto_stream_.handshake_complete()) { |
21 DLOG(INFO) << "Crypto handshake not complete, no outgoing stream created."; | 22 DLOG(INFO) << "Crypto handshake not complete, no outgoing stream created."; |
22 return NULL; | 23 return NULL; |
23 } | 24 } |
24 if (GetNumOpenStreams() >= get_max_open_streams()) { | 25 if (GetNumOpenStreams() >= get_max_open_streams()) { |
25 DLOG(INFO) << "Failed to create a new outgoing stream. " | 26 DLOG(INFO) << "Failed to create a new outgoing stream. " |
26 << "Already " << GetNumOpenStreams() << " open."; | 27 << "Already " << GetNumOpenStreams() << " open."; |
27 return NULL; | 28 return NULL; |
28 } | 29 } |
29 QuicReliableClientStream* stream = | 30 QuicReliableClientStream* stream = |
30 new QuicReliableClientStream(GetNextStreamId(), this); | 31 new QuicReliableClientStream(GetNextStreamId(), this); |
| 32 streams_[stream->id()] = stream; |
31 | 33 |
32 ActivateStream(stream); | 34 ActivateStream(stream); |
33 return stream; | 35 return stream; |
34 } | 36 } |
35 | 37 |
36 QuicCryptoClientStream* QuicClientSession::GetCryptoStream() { | 38 QuicCryptoClientStream* QuicClientSession::GetCryptoStream() { |
37 return &crypto_stream_; | 39 return &crypto_stream_; |
38 }; | 40 }; |
39 | 41 |
40 int QuicClientSession::CryptoConnect(const CompletionCallback& callback) { | 42 int QuicClientSession::CryptoConnect(const CompletionCallback& callback) { |
41 CryptoHandshakeMessage message; | 43 CryptoHandshakeMessage message; |
42 message.tag = kCHLO; | 44 message.tag = kCHLO; |
43 crypto_stream_.SendHandshakeMessage(message); | 45 crypto_stream_.SendHandshakeMessage(message); |
44 | 46 |
45 if (IsCryptoHandshakeComplete()) { | 47 if (IsCryptoHandshakeComplete()) { |
46 return OK; | 48 return OK; |
47 } | 49 } |
48 | 50 |
49 callback_ = callback; | 51 callback_ = callback; |
50 return ERR_IO_PENDING; | 52 return ERR_IO_PENDING; |
51 } | 53 } |
52 | 54 |
53 ReliableQuicStream* QuicClientSession::CreateIncomingReliableStream( | 55 ReliableQuicStream* QuicClientSession::CreateIncomingReliableStream( |
54 QuicStreamId id) { | 56 QuicStreamId id) { |
55 DLOG(ERROR) << "Server push not supported"; | 57 DLOG(ERROR) << "Server push not supported"; |
56 return NULL; | 58 return NULL; |
57 } | 59 } |
58 | 60 |
| 61 void QuicClientSession::CloseStream(QuicStreamId stream_id) { |
| 62 QuicSession::CloseStream(stream_id); |
| 63 |
| 64 StreamMap::iterator it = streams_.find(stream_id); |
| 65 DCHECK(it != streams_.end()); |
| 66 if (it != streams_.end()) { |
| 67 ReliableQuicStream* stream = it->second; |
| 68 streams_.erase(it); |
| 69 delete stream; |
| 70 } |
| 71 } |
| 72 |
59 void QuicClientSession::OnCryptoHandshakeComplete(QuicErrorCode error) { | 73 void QuicClientSession::OnCryptoHandshakeComplete(QuicErrorCode error) { |
60 if (!callback_.is_null()) { | 74 if (!callback_.is_null()) { |
61 callback_.Run(error == QUIC_NO_ERROR ? OK : ERR_UNEXPECTED); | 75 callback_.Run(error == QUIC_NO_ERROR ? OK : ERR_UNEXPECTED); |
62 } | 76 } |
63 } | 77 } |
64 | 78 |
65 } // namespace net | 79 } // namespace net |
OLD | NEW |