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 "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/string_number_conversions.h" |
| 10 #include "base/values.h" |
9 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
10 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
11 #include "net/quic/quic_connection_helper.h" | 13 #include "net/quic/quic_connection_helper.h" |
12 #include "net/quic/quic_stream_factory.h" | 14 #include "net/quic/quic_stream_factory.h" |
13 #include "net/udp/datagram_client_socket.h" | 15 #include "net/udp/datagram_client_socket.h" |
14 | 16 |
15 namespace net { | 17 namespace net { |
16 | 18 |
17 QuicClientSession::QuicClientSession(QuicConnection* connection, | 19 QuicClientSession::QuicClientSession(QuicConnection* connection, |
18 QuicConnectionHelper* helper, | 20 QuicConnectionHelper* helper, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 void QuicClientSession::CloseSessionOnError(int error) { | 108 void QuicClientSession::CloseSessionOnError(int error) { |
107 while (!streams()->empty()) { | 109 while (!streams()->empty()) { |
108 ReliableQuicStream* stream = streams()->begin()->second; | 110 ReliableQuicStream* stream = streams()->begin()->second; |
109 QuicStreamId id = stream->id(); | 111 QuicStreamId id = stream->id(); |
110 static_cast<QuicReliableClientStream*>(stream)->OnError(error); | 112 static_cast<QuicReliableClientStream*>(stream)->OnError(error); |
111 CloseStream(id); | 113 CloseStream(id); |
112 } | 114 } |
113 stream_factory_->OnSessionClose(this); | 115 stream_factory_->OnSessionClose(this); |
114 } | 116 } |
115 | 117 |
| 118 Value* QuicClientSession::GetInfoAsValue(const HostPortPair& pair) const { |
| 119 DictionaryValue* dict = new DictionaryValue(); |
| 120 dict->SetString("host_port_pair", pair.ToString()); |
| 121 dict->SetInteger("open_streams", GetNumOpenStreams()); |
| 122 dict->SetString("peer_address", peer_address().ToString()); |
| 123 dict->SetString("guid", base::Uint64ToString(guid())); |
| 124 return dict; |
| 125 } |
| 126 |
116 void QuicClientSession::OnReadComplete(int result) { | 127 void QuicClientSession::OnReadComplete(int result) { |
117 read_pending_ = false; | 128 read_pending_ = false; |
118 // TODO(rch): Inform the connection about the result. | 129 // TODO(rch): Inform the connection about the result. |
119 if (result > 0) { | 130 if (result > 0) { |
120 scoped_refptr<IOBufferWithSize> buffer(read_buffer_); | 131 scoped_refptr<IOBufferWithSize> buffer(read_buffer_); |
121 read_buffer_ = new IOBufferWithSize(kMaxPacketSize); | 132 read_buffer_ = new IOBufferWithSize(kMaxPacketSize); |
122 QuicEncryptedPacket packet(buffer->data(), result); | 133 QuicEncryptedPacket packet(buffer->data(), result); |
123 IPEndPoint local_address; | 134 IPEndPoint local_address; |
124 IPEndPoint peer_address; | 135 IPEndPoint peer_address; |
125 helper_->GetLocalAddress(&local_address); | 136 helper_->GetLocalAddress(&local_address); |
126 helper_->GetPeerAddress(&peer_address); | 137 helper_->GetPeerAddress(&peer_address); |
127 // ProcessUdpPacket might result in |this| being deleted, so we | 138 // ProcessUdpPacket might result in |this| being deleted, so we |
128 // use a weak pointer to be safe. | 139 // use a weak pointer to be safe. |
129 connection()->ProcessUdpPacket(local_address, peer_address, packet); | 140 connection()->ProcessUdpPacket(local_address, peer_address, packet); |
130 if (!connection()->connected()) { | 141 if (!connection()->connected()) { |
131 stream_factory_->OnSessionClose(this); | 142 stream_factory_->OnSessionClose(this); |
132 return; | 143 return; |
133 } | 144 } |
134 StartReading(); | 145 StartReading(); |
135 } | 146 } |
136 } | 147 } |
137 | 148 |
138 } // namespace net | 149 } // namespace net |
OLD | NEW |