Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: net/spdy/spdy_session.cc

Issue 8230037: Send PING to check the status of the SPDY connection. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "net/spdy/spdy_session.h" 5 #include "net/spdy/spdy_session.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/linked_ptr.h" 9 #include "base/memory/linked_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 165 }
166 166
167 private: 167 private:
168 ~NetLogSpdyRstParameter() {} 168 ~NetLogSpdyRstParameter() {}
169 const spdy::SpdyStreamId stream_id_; 169 const spdy::SpdyStreamId stream_id_;
170 const int status_; 170 const int status_;
171 171
172 DISALLOW_COPY_AND_ASSIGN(NetLogSpdyRstParameter); 172 DISALLOW_COPY_AND_ASSIGN(NetLogSpdyRstParameter);
173 }; 173 };
174 174
175 class NetLogSpdyPingParameter : public NetLog::EventParameters {
176 public:
177 NetLogSpdyPingParameter(spdy::SpdyStreamId stream_id,
178 uint32 unique_id)
179 : stream_id_(stream_id),
180 unique_id_(unique_id) {}
181
182 virtual Value* ToValue() const {
183 DictionaryValue* dict = new DictionaryValue();
184 dict->SetInteger("stream_id", static_cast<int>(stream_id_));
185 dict->SetInteger("unique_id", unique_id_);
186 return dict;
187 }
188
189 private:
190 ~NetLogSpdyPingParameter() {}
191 const spdy::SpdyStreamId stream_id_;
192 const uint32 unique_id_;
193
194 DISALLOW_COPY_AND_ASSIGN(NetLogSpdyPingParameter);
195 };
196
175 class NetLogSpdyGoAwayParameter : public NetLog::EventParameters { 197 class NetLogSpdyGoAwayParameter : public NetLog::EventParameters {
176 public: 198 public:
177 NetLogSpdyGoAwayParameter(spdy::SpdyStreamId last_stream_id, 199 NetLogSpdyGoAwayParameter(spdy::SpdyStreamId last_stream_id,
178 int active_streams, 200 int active_streams,
179 int unclaimed_streams) 201 int unclaimed_streams)
180 : last_stream_id_(last_stream_id), 202 : last_stream_id_(last_stream_id),
181 active_streams_(active_streams), 203 active_streams_(active_streams),
182 unclaimed_streams_(unclaimed_streams) {} 204 unclaimed_streams_(unclaimed_streams) {}
183 205
184 virtual Value* ToValue() const { 206 virtual Value* ToValue() const {
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdyPriorityCount", 475 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdyPriorityCount",
454 static_cast<int>(priority), 0, 10, 11); 476 static_cast<int>(priority), 0, 10, 11);
455 477
456 // TODO(mbelshe): Optimize memory allocations 478 // TODO(mbelshe): Optimize memory allocations
457 DCHECK(priority >= net::HIGHEST && priority < net::NUM_PRIORITIES); 479 DCHECK(priority >= net::HIGHEST && priority < net::NUM_PRIORITIES);
458 480
459 DCHECK_EQ(active_streams_[stream_id].get(), stream.get()); 481 DCHECK_EQ(active_streams_[stream_id].get(), stream.get());
460 return OK; 482 return OK;
461 } 483 }
462 484
485 int SpdySession::WritePingFrame(spdy::SpdyStreamId stream_id) {
486 // Find our stream
487 if (!IsStreamActive(stream_id))
488 return ERR_INVALID_SPDY_STREAM;
489 const scoped_refptr<SpdyStream>& stream = active_streams_[stream_id];
490 CHECK_EQ(stream->stream_id(), stream_id);
491
492 static uint32 unique_id = 1;
493 unique_id += 2;
494 scoped_ptr<spdy::SpdyPingControlFrame> ping_frame(
495 spdy_framer_.CreatePingFrame(unique_id));
496 QueueFrame(ping_frame.get(), SPDY_PRIORITY_HIGHEST, stream);
497
498 base::StatsCounter spdy_requests("spdy.requests");
499 spdy_requests.Increment();
500 streams_initiated_count_++;
501 sent_ping_ = true;
502 received_ping_ = false;
503 if (net_log().IsLoggingAllEvents()) {
504 net_log().AddEvent(
505 NetLog::TYPE_SPDY_SESSION_PING,
506 make_scoped_refptr(new NetLogSpdyPingParameter(stream_id, unique_id)));
willchan no longer on Chromium 2011/10/12 05:41:06 There's no need to log the stream_id, just the uni
ramant (doing other things) 2011/10/13 21:41:14 Done.
507 }
508
509 return ERR_IO_PENDING;
510 }
511
463 int SpdySession::WriteSynStream( 512 int SpdySession::WriteSynStream(
464 spdy::SpdyStreamId stream_id, 513 spdy::SpdyStreamId stream_id,
465 RequestPriority priority, 514 RequestPriority priority,
466 spdy::SpdyControlFlags flags, 515 spdy::SpdyControlFlags flags,
467 const linked_ptr<spdy::SpdyHeaderBlock>& headers) { 516 const linked_ptr<spdy::SpdyHeaderBlock>& headers) {
468 // Find our stream 517 // Find our stream
469 if (!IsStreamActive(stream_id)) 518 if (!IsStreamActive(stream_id))
470 return ERR_INVALID_SPDY_STREAM; 519 return ERR_INVALID_SPDY_STREAM;
471 const scoped_refptr<SpdyStream>& stream = active_streams_[stream_id]; 520 const scoped_refptr<SpdyStream>& stream = active_streams_[stream_id];
472 CHECK_EQ(stream->stream_id(), stream_id); 521 CHECK_EQ(stream->stream_id(), stream_id);
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 return; 1268 return;
1220 } 1269 }
1221 } 1270 }
1222 1271
1223 frames_received_++; 1272 frames_received_++;
1224 1273
1225 switch (type) { 1274 switch (type) {
1226 case spdy::GOAWAY: 1275 case spdy::GOAWAY:
1227 OnGoAway(*reinterpret_cast<const spdy::SpdyGoAwayControlFrame*>(frame)); 1276 OnGoAway(*reinterpret_cast<const spdy::SpdyGoAwayControlFrame*>(frame));
1228 break; 1277 break;
1278 case spdy::PING:
1279 OnPing(*reinterpret_cast<const spdy::SpdyPingControlFrame*>(frame));
1280 break;
1229 case spdy::SETTINGS: 1281 case spdy::SETTINGS:
1230 OnSettings( 1282 OnSettings(
1231 *reinterpret_cast<const spdy::SpdySettingsControlFrame*>(frame)); 1283 *reinterpret_cast<const spdy::SpdySettingsControlFrame*>(frame));
1232 break; 1284 break;
1233 case spdy::RST_STREAM: 1285 case spdy::RST_STREAM:
1234 OnRst(*reinterpret_cast<const spdy::SpdyRstStreamControlFrame*>(frame)); 1286 OnRst(*reinterpret_cast<const spdy::SpdyRstStreamControlFrame*>(frame));
1235 break; 1287 break;
1236 case spdy::SYN_STREAM: 1288 case spdy::SYN_STREAM:
1237 OnSyn(*reinterpret_cast<const spdy::SpdySynStreamControlFrame*>(frame), 1289 OnSyn(*reinterpret_cast<const spdy::SpdySynStreamControlFrame*>(frame),
1238 headers); 1290 headers);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 CloseAllStreams(net::ERR_ABORTED); 1357 CloseAllStreams(net::ERR_ABORTED);
1306 1358
1307 // TODO(willchan): Cancel any streams that are past the GoAway frame's 1359 // TODO(willchan): Cancel any streams that are past the GoAway frame's
1308 // |last_accepted_stream_id|. 1360 // |last_accepted_stream_id|.
1309 1361
1310 // Don't bother killing any streams that are still reading. They'll either 1362 // Don't bother killing any streams that are still reading. They'll either
1311 // complete successfully or get an ERR_CONNECTION_CLOSED when the socket is 1363 // complete successfully or get an ERR_CONNECTION_CLOSED when the socket is
1312 // closed. 1364 // closed.
1313 } 1365 }
1314 1366
1367 void SpdySession::OnPing(const spdy::SpdyPingControlFrame& frame) {
1368 sent_ping_ = false;
1369 received_ping_ = true;
1370 net_log_.AddEvent(
1371 NetLog::TYPE_SPDY_SESSION_PING,
1372 make_scoped_refptr(new NetLogIntegerParameter("unique_id",
1373 frame.unique_id())));
1374 // TODO(rtenneti): we should verify unique_id.
1375 }
1376
1315 void SpdySession::OnSettings(const spdy::SpdySettingsControlFrame& frame) { 1377 void SpdySession::OnSettings(const spdy::SpdySettingsControlFrame& frame) {
1316 spdy::SpdySettings settings; 1378 spdy::SpdySettings settings;
1317 if (spdy_framer_.ParseSettings(&frame, &settings)) { 1379 if (spdy_framer_.ParseSettings(&frame, &settings)) {
1318 HandleSettings(settings); 1380 HandleSettings(settings);
1319 spdy_settings_->Set(host_port_pair(), settings); 1381 spdy_settings_->Set(host_port_pair(), settings);
1320 } 1382 }
1321 1383
1322 received_settings_ = true; 1384 received_settings_ = true;
1323 1385
1324 net_log_.AddEvent( 1386 net_log_.AddEvent(
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 if (it == pending_callback_map_.end()) 1593 if (it == pending_callback_map_.end())
1532 return; 1594 return;
1533 1595
1534 OldCompletionCallback* callback = it->second.callback; 1596 OldCompletionCallback* callback = it->second.callback;
1535 int result = it->second.result; 1597 int result = it->second.result;
1536 pending_callback_map_.erase(it); 1598 pending_callback_map_.erase(it);
1537 callback->Run(result); 1599 callback->Run(result);
1538 } 1600 }
1539 1601
1540 } // namespace net 1602 } // namespace net
OLDNEW
« net/spdy/spdy_session.h ('K') | « net/spdy/spdy_session.h ('k') | net/spdy/spdy_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698