| 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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 spdy_framer_.Reset(); | 553 spdy_framer_.Reset(); |
| 554 } | 554 } |
| 555 | 555 |
| 556 if (state_ != CLOSED) | 556 if (state_ != CLOSED) |
| 557 ReadSocket(); | 557 ReadSocket(); |
| 558 } | 558 } |
| 559 | 559 |
| 560 void SpdySession::OnWriteComplete(int result) { | 560 void SpdySession::OnWriteComplete(int result) { |
| 561 DCHECK(write_pending_); | 561 DCHECK(write_pending_); |
| 562 DCHECK(in_flight_write_.size()); | 562 DCHECK(in_flight_write_.size()); |
| 563 DCHECK(result != 0); // This shouldn't happen for write. | 563 DCHECK_NE(result, 0); // This shouldn't happen for write. |
| 564 | 564 |
| 565 write_pending_ = false; | 565 write_pending_ = false; |
| 566 | 566 |
| 567 scoped_refptr<SpdyStream> stream = in_flight_write_.stream(); | 567 scoped_refptr<SpdyStream> stream = in_flight_write_.stream(); |
| 568 | 568 |
| 569 LOG(INFO) << "Spdy write complete (result=" << result << ")" | 569 LOG(INFO) << "Spdy write complete (result=" << result << ")" |
| 570 << (stream ? " for stream " + stream->stream_id() : ""); | 570 << (stream ? std::string(" for stream ") + |
| 571 IntToString(stream->stream_id()) : ""); |
| 571 | 572 |
| 572 if (result >= 0) { | 573 if (result >= 0) { |
| 573 // It should not be possible to have written more bytes than our | 574 // It should not be possible to have written more bytes than our |
| 574 // in_flight_write_. | 575 // in_flight_write_. |
| 575 DCHECK_LE(result, in_flight_write_.buffer()->BytesRemaining()); | 576 DCHECK_LE(result, in_flight_write_.buffer()->BytesRemaining()); |
| 576 | 577 |
| 577 in_flight_write_.buffer()->DidConsume(result); | 578 in_flight_write_.buffer()->DidConsume(result); |
| 578 | 579 |
| 579 // We only notify the stream when we've fully written the pending frame. | 580 // We only notify the stream when we've fully written the pending frame. |
| 580 if (!in_flight_write_.buffer()->BytesRemaining()) { | 581 if (!in_flight_write_.buffer()->BytesRemaining()) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 // again when the socket connection completes. If the socket is | 669 // again when the socket connection completes. If the socket is |
| 669 // closed, just return. | 670 // closed, just return. |
| 670 if (state_ < CONNECTED || state_ == CLOSED) | 671 if (state_ < CONNECTED || state_ == CLOSED) |
| 671 return; | 672 return; |
| 672 | 673 |
| 673 if (write_pending_) // Another write is in progress still. | 674 if (write_pending_) // Another write is in progress still. |
| 674 return; | 675 return; |
| 675 | 676 |
| 676 // Loop sending frames until we've sent everything or until the write | 677 // Loop sending frames until we've sent everything or until the write |
| 677 // returns error (or ERR_IO_PENDING). | 678 // returns error (or ERR_IO_PENDING). |
| 678 while (in_flight_write_.buffer() || queue_.size()) { | 679 while (in_flight_write_.buffer() || !queue_.empty()) { |
| 679 if (!in_flight_write_.buffer()) { | 680 if (!in_flight_write_.buffer()) { |
| 680 // Grab the next SpdyFrame to send. | 681 // Grab the next SpdyFrame to send. |
| 681 SpdyIOBuffer next_buffer = queue_.top(); | 682 SpdyIOBuffer next_buffer = queue_.top(); |
| 682 queue_.pop(); | 683 queue_.pop(); |
| 683 | 684 |
| 684 // We've deferred compression until just before we write it to the socket, | 685 // We've deferred compression until just before we write it to the socket, |
| 685 // which is now. At this time, we don't compress our data frames. | 686 // which is now. At this time, we don't compress our data frames. |
| 686 spdy::SpdyFrame uncompressed_frame(next_buffer.buffer()->data(), false); | 687 spdy::SpdyFrame uncompressed_frame(next_buffer.buffer()->data(), false); |
| 687 size_t size; | 688 size_t size; |
| 688 if (spdy_framer_.IsCompressible(&uncompressed_frame)) { | 689 if (spdy_framer_.IsCompressible(&uncompressed_frame)) { |
| 689 scoped_ptr<spdy::SpdyFrame> compressed_frame( | 690 scoped_ptr<spdy::SpdyFrame> compressed_frame( |
| 690 spdy_framer_.CompressFrame(&uncompressed_frame)); | 691 spdy_framer_.CompressFrame(&uncompressed_frame)); |
| 691 if (!compressed_frame.get()) { | 692 if (!compressed_frame.get()) { |
| 692 LOG(ERROR) << "SPDY Compression failure"; | 693 LOG(ERROR) << "SPDY Compression failure"; |
| 693 CloseSessionOnError(net::ERR_SPDY_PROTOCOL_ERROR); | 694 CloseSessionOnError(net::ERR_SPDY_PROTOCOL_ERROR); |
| 694 return; | 695 return; |
| 695 } | 696 } |
| 696 | 697 |
| 697 size = compressed_frame->length() + spdy::SpdyFrame::size(); | 698 size = compressed_frame->length() + spdy::SpdyFrame::size(); |
| 698 | 699 |
| 699 DCHECK(size > 0); | 700 DCHECK_GT(size, 0u); |
| 700 | 701 |
| 701 // TODO(mbelshe): We have too much copying of data here. | 702 // TODO(mbelshe): We have too much copying of data here. |
| 702 IOBufferWithSize* buffer = new IOBufferWithSize(size); | 703 IOBufferWithSize* buffer = new IOBufferWithSize(size); |
| 703 memcpy(buffer->data(), compressed_frame->data(), size); | 704 memcpy(buffer->data(), compressed_frame->data(), size); |
| 704 | 705 |
| 705 // Attempt to send the frame. | 706 // Attempt to send the frame. |
| 706 in_flight_write_ = SpdyIOBuffer(buffer, size, 0, next_buffer.stream()); | 707 in_flight_write_ = SpdyIOBuffer(buffer, size, 0, next_buffer.stream()); |
| 707 } else { | 708 } else { |
| 708 size = uncompressed_frame.length() + spdy::SpdyFrame::size(); | 709 size = uncompressed_frame.length() + spdy::SpdyFrame::size(); |
| 709 in_flight_write_ = next_buffer; | 710 in_flight_write_ = next_buffer; |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 if (settings.empty()) | 1124 if (settings.empty()) |
| 1124 return; | 1125 return; |
| 1125 | 1126 |
| 1126 // Create the SETTINGS frame and send it. | 1127 // Create the SETTINGS frame and send it. |
| 1127 scoped_ptr<spdy::SpdySettingsControlFrame> settings_frame( | 1128 scoped_ptr<spdy::SpdySettingsControlFrame> settings_frame( |
| 1128 spdy_framer_.CreateSettings(settings)); | 1129 spdy_framer_.CreateSettings(settings)); |
| 1129 QueueFrame(settings_frame.get(), 0, NULL); | 1130 QueueFrame(settings_frame.get(), 0, NULL); |
| 1130 } | 1131 } |
| 1131 | 1132 |
| 1132 } // namespace net | 1133 } // namespace net |
| OLD | NEW |