OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
(...skipping 515 matching lines...) Loading... |
526 // our read. | 526 // our read. |
527 WriteSocketLater(); | 527 WriteSocketLater(); |
528 ReadSocket(); | 528 ReadSocket(); |
529 } else { | 529 } else { |
530 DCHECK_LT(result, 0); // It should be an error, not a byte count. | 530 DCHECK_LT(result, 0); // It should be an error, not a byte count. |
531 CloseSessionOnError(static_cast<net::Error>(result)); | 531 CloseSessionOnError(static_cast<net::Error>(result)); |
532 } | 532 } |
533 } | 533 } |
534 | 534 |
535 void SpdySession::OnReadComplete(int bytes_read) { | 535 void SpdySession::OnReadComplete(int bytes_read) { |
536 DLOG(INFO) << " >> " << __FUNCTION__ << "()"; | |
537 // Parse a frame. For now this code requires that the frame fit into our | 536 // Parse a frame. For now this code requires that the frame fit into our |
538 // buffer (32KB). | 537 // buffer (32KB). |
539 // TODO(mbelshe): support arbitrarily large frames! | 538 // TODO(mbelshe): support arbitrarily large frames! |
540 | 539 |
541 LOG(INFO) << "Spdy socket read: " << bytes_read << " bytes"; | 540 LOG(INFO) << "Spdy socket read: " << bytes_read << " bytes"; |
542 | 541 |
543 read_pending_ = false; | 542 read_pending_ = false; |
544 | 543 |
545 if (bytes_read <= 0) { | 544 if (bytes_read <= 0) { |
546 // Session is tearing down. | 545 // Session is tearing down. |
(...skipping 18 matching lines...) Loading... |
565 data += bytes_processed; | 564 data += bytes_processed; |
566 if (spdy_framer_.state() == spdy::SpdyFramer::SPDY_DONE) | 565 if (spdy_framer_.state() == spdy::SpdyFramer::SPDY_DONE) |
567 spdy_framer_.Reset(); | 566 spdy_framer_.Reset(); |
568 } | 567 } |
569 | 568 |
570 if (state_ != CLOSED) | 569 if (state_ != CLOSED) |
571 ReadSocket(); | 570 ReadSocket(); |
572 } | 571 } |
573 | 572 |
574 void SpdySession::OnWriteComplete(int result) { | 573 void SpdySession::OnWriteComplete(int result) { |
575 DLOG(INFO) << " >> " << __FUNCTION__ << "()"; | |
576 DCHECK(write_pending_); | 574 DCHECK(write_pending_); |
577 DCHECK(in_flight_write_.size()); | 575 DCHECK(in_flight_write_.size()); |
578 DCHECK(result != 0); // This shouldn't happen for write. | 576 DCHECK(result != 0); // This shouldn't happen for write. |
579 | 577 |
580 write_pending_ = false; | 578 write_pending_ = false; |
581 | 579 |
582 LOG(INFO) << "Spdy write complete (result=" << result << ") for stream: " | 580 LOG(INFO) << "Spdy write complete (result=" << result << ") for stream: " |
583 << in_flight_write_.stream()->stream_id(); | 581 << in_flight_write_.stream()->stream_id(); |
584 | 582 |
585 if (result >= 0) { | 583 if (result >= 0) { |
(...skipping 430 matching lines...) Loading... |
1016 } | 1014 } |
1017 | 1015 |
1018 scoped_refptr<SpdyStream> stream = active_streams_[stream_id]; | 1016 scoped_refptr<SpdyStream> stream = active_streams_[stream_id]; |
1019 CHECK_EQ(stream->stream_id(), stream_id); | 1017 CHECK_EQ(stream->stream_id(), stream_id); |
1020 CHECK(!stream->cancelled()); | 1018 CHECK(!stream->cancelled()); |
1021 | 1019 |
1022 Respond(headers, stream); | 1020 Respond(headers, stream); |
1023 } | 1021 } |
1024 | 1022 |
1025 void SpdySession::OnControl(const spdy::SpdyControlFrame* frame) { | 1023 void SpdySession::OnControl(const spdy::SpdyControlFrame* frame) { |
1026 DLOG(INFO) << " >> " << __FUNCTION__ << "()"; | |
1027 spdy::SpdyHeaderBlock headers; | 1024 spdy::SpdyHeaderBlock headers; |
1028 uint32 type = frame->type(); | 1025 uint32 type = frame->type(); |
1029 if (type == spdy::SYN_STREAM || type == spdy::SYN_REPLY) { | 1026 if (type == spdy::SYN_STREAM || type == spdy::SYN_REPLY) { |
1030 if (!spdy_framer_.ParseHeaderBlock(frame, &headers)) { | 1027 if (!spdy_framer_.ParseHeaderBlock(frame, &headers)) { |
1031 LOG(WARNING) << "Could not parse Spdy Control Frame Header"; | 1028 LOG(WARNING) << "Could not parse Spdy Control Frame Header"; |
1032 // TODO(mbelshe): Error the session? | 1029 // TODO(mbelshe): Error the session? |
1033 return; | 1030 return; |
1034 } | 1031 } |
1035 } | 1032 } |
1036 | 1033 |
(...skipping 37 matching lines...) Loading... |
1074 LOG(ERROR) << "Spdy stream closed: " << frame.status(); | 1071 LOG(ERROR) << "Spdy stream closed: " << frame.status(); |
1075 // TODO(mbelshe): Map from Spdy-protocol errors to something sensical. | 1072 // TODO(mbelshe): Map from Spdy-protocol errors to something sensical. |
1076 // For now, it doesn't matter much - it is a protocol error. | 1073 // For now, it doesn't matter much - it is a protocol error. |
1077 stream->OnClose(ERR_FAILED); | 1074 stream->OnClose(ERR_FAILED); |
1078 } | 1075 } |
1079 | 1076 |
1080 DeactivateStream(stream_id); | 1077 DeactivateStream(stream_id); |
1081 } | 1078 } |
1082 | 1079 |
1083 void SpdySession::OnGoAway(const spdy::SpdyGoAwayControlFrame& frame) { | 1080 void SpdySession::OnGoAway(const spdy::SpdyGoAwayControlFrame& frame) { |
1084 DLOG(INFO) << " >> " << __FUNCTION__ << "()"; | |
1085 session_->spdy_session_pool()->Remove(this); | 1081 session_->spdy_session_pool()->Remove(this); |
1086 | 1082 |
1087 // TODO(willchan): Cancel any streams that are past the GoAway frame's | 1083 // TODO(willchan): Cancel any streams that are past the GoAway frame's |
1088 // |last_accepted_stream_id|. | 1084 // |last_accepted_stream_id|. |
1089 | 1085 |
1090 // Don't bother killing any streams that are still reading. They'll either | 1086 // Don't bother killing any streams that are still reading. They'll either |
1091 // complete successfully or get an ERR_CONNECTION_CLOSED when the socket is | 1087 // complete successfully or get an ERR_CONNECTION_CLOSED when the socket is |
1092 // closed. | 1088 // closed. |
1093 } | 1089 } |
1094 | 1090 |
1095 } // namespace net | 1091 } // namespace net |
OLD | NEW |