OLD | NEW |
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 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 | 708 |
709 // We only notify the stream when we've fully written the pending frame. | 709 // We only notify the stream when we've fully written the pending frame. |
710 if (!in_flight_write_.buffer()->BytesRemaining()) { | 710 if (!in_flight_write_.buffer()->BytesRemaining()) { |
711 if (stream) { | 711 if (stream) { |
712 // Report the number of bytes written to the caller, but exclude the | 712 // Report the number of bytes written to the caller, but exclude the |
713 // frame size overhead. NOTE: if this frame was compressed the | 713 // frame size overhead. NOTE: if this frame was compressed the |
714 // reported bytes written is the compressed size, not the original | 714 // reported bytes written is the compressed size, not the original |
715 // size. | 715 // size. |
716 if (result > 0) { | 716 if (result > 0) { |
717 result = in_flight_write_.buffer()->size(); | 717 result = in_flight_write_.buffer()->size(); |
718 DCHECK_GE(result, static_cast<int>(spdy::SpdyFrame::size())); | 718 DCHECK_GE(result, static_cast<int>(spdy::SpdyFrame::kHeaderSize)); |
719 result -= static_cast<int>(spdy::SpdyFrame::size()); | 719 result -= static_cast<int>(spdy::SpdyFrame::kHeaderSize); |
720 } | 720 } |
721 | 721 |
722 // It is possible that the stream was cancelled while we were writing | 722 // It is possible that the stream was cancelled while we were writing |
723 // to the socket. | 723 // to the socket. |
724 if (!stream->cancelled()) | 724 if (!stream->cancelled()) |
725 stream->OnWriteComplete(result); | 725 stream->OnWriteComplete(result); |
726 } | 726 } |
727 | 727 |
728 // Cleanup the write which just completed. | 728 // Cleanup the write which just completed. |
729 in_flight_write_.release(); | 729 in_flight_write_.release(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 size_t size; | 819 size_t size; |
820 if (spdy_framer_.IsCompressible(uncompressed_frame)) { | 820 if (spdy_framer_.IsCompressible(uncompressed_frame)) { |
821 scoped_ptr<spdy::SpdyFrame> compressed_frame( | 821 scoped_ptr<spdy::SpdyFrame> compressed_frame( |
822 spdy_framer_.CompressFrame(uncompressed_frame)); | 822 spdy_framer_.CompressFrame(uncompressed_frame)); |
823 if (!compressed_frame.get()) { | 823 if (!compressed_frame.get()) { |
824 LOG(ERROR) << "SPDY Compression failure"; | 824 LOG(ERROR) << "SPDY Compression failure"; |
825 CloseSessionOnError(net::ERR_SPDY_PROTOCOL_ERROR, true); | 825 CloseSessionOnError(net::ERR_SPDY_PROTOCOL_ERROR, true); |
826 return; | 826 return; |
827 } | 827 } |
828 | 828 |
829 size = compressed_frame->length() + spdy::SpdyFrame::size(); | 829 size = compressed_frame->length() + spdy::SpdyFrame::kHeaderSize; |
830 | 830 |
831 DCHECK_GT(size, 0u); | 831 DCHECK_GT(size, 0u); |
832 | 832 |
833 // TODO(mbelshe): We have too much copying of data here. | 833 // TODO(mbelshe): We have too much copying of data here. |
834 IOBufferWithSize* buffer = new IOBufferWithSize(size); | 834 IOBufferWithSize* buffer = new IOBufferWithSize(size); |
835 memcpy(buffer->data(), compressed_frame->data(), size); | 835 memcpy(buffer->data(), compressed_frame->data(), size); |
836 | 836 |
837 // Attempt to send the frame. | 837 // Attempt to send the frame. |
838 in_flight_write_ = SpdyIOBuffer(buffer, size, 0, next_buffer.stream()); | 838 in_flight_write_ = SpdyIOBuffer(buffer, size, 0, next_buffer.stream()); |
839 } else { | 839 } else { |
840 size = uncompressed_frame.length() + spdy::SpdyFrame::size(); | 840 size = uncompressed_frame.length() + spdy::SpdyFrame::kHeaderSize; |
841 in_flight_write_ = next_buffer; | 841 in_flight_write_ = next_buffer; |
842 } | 842 } |
843 } else { | 843 } else { |
844 DCHECK(in_flight_write_.buffer()->BytesRemaining()); | 844 DCHECK(in_flight_write_.buffer()->BytesRemaining()); |
845 } | 845 } |
846 | 846 |
847 write_pending_ = true; | 847 write_pending_ = true; |
848 int rv = connection_->socket()->Write(in_flight_write_.buffer(), | 848 int rv = connection_->socket()->Write(in_flight_write_.buffer(), |
849 in_flight_write_.buffer()->BytesRemaining(), &write_callback_); | 849 in_flight_write_.buffer()->BytesRemaining(), &write_callback_); |
850 if (rv == net::ERR_IO_PENDING) | 850 if (rv == net::ERR_IO_PENDING) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 int id = stream_hi_water_mark_; | 899 int id = stream_hi_water_mark_; |
900 stream_hi_water_mark_ += 2; | 900 stream_hi_water_mark_ += 2; |
901 if (stream_hi_water_mark_ > 0x7fff) | 901 if (stream_hi_water_mark_ > 0x7fff) |
902 stream_hi_water_mark_ = 1; | 902 stream_hi_water_mark_ = 1; |
903 return id; | 903 return id; |
904 } | 904 } |
905 | 905 |
906 void SpdySession::QueueFrame(spdy::SpdyFrame* frame, | 906 void SpdySession::QueueFrame(spdy::SpdyFrame* frame, |
907 spdy::SpdyPriority priority, | 907 spdy::SpdyPriority priority, |
908 SpdyStream* stream) { | 908 SpdyStream* stream) { |
909 int length = spdy::SpdyFrame::size() + frame->length(); | 909 int length = spdy::SpdyFrame::kHeaderSize + frame->length(); |
910 IOBuffer* buffer = new IOBuffer(length); | 910 IOBuffer* buffer = new IOBuffer(length); |
911 memcpy(buffer->data(), frame->data(), length); | 911 memcpy(buffer->data(), frame->data(), length); |
912 queue_.push(SpdyIOBuffer(buffer, length, priority, stream)); | 912 queue_.push(SpdyIOBuffer(buffer, length, priority, stream)); |
913 | 913 |
914 WriteSocketLater(); | 914 WriteSocketLater(); |
915 } | 915 } |
916 | 916 |
917 void SpdySession::CloseSessionOnError(net::Error err, bool remove_from_pool) { | 917 void SpdySession::CloseSessionOnError(net::Error err, bool remove_from_pool) { |
918 // Closing all streams can have a side-effect of dropping the last reference | 918 // Closing all streams can have a side-effect of dropping the last reference |
919 // to |this|. Hold a reference through this function. | 919 // to |this|. Hold a reference through this function. |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1733 if (it == pending_callback_map_.end()) | 1733 if (it == pending_callback_map_.end()) |
1734 return; | 1734 return; |
1735 | 1735 |
1736 OldCompletionCallback* callback = it->second.callback; | 1736 OldCompletionCallback* callback = it->second.callback; |
1737 int result = it->second.result; | 1737 int result = it->second.result; |
1738 pending_callback_map_.erase(it); | 1738 pending_callback_map_.erase(it); |
1739 callback->Run(result); | 1739 callback->Run(result); |
1740 } | 1740 } |
1741 | 1741 |
1742 } // namespace net | 1742 } // namespace net |
OLD | NEW |