Chromium Code Reviews
Help | Chromium Project | Sign in
(599)

Side by Side Diff: net/quic/reliable_quic_stream.cc

Issue 11300020: Add QuicStream and friends to QUIC code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: License Created 1 year, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/quic/reliable_quic_stream.h"
6
7 #include "net/quic/quic_session.h"
8
9 using base::StringPiece;
10
11 namespace net {
12
13 ReliableQuicStream::ReliableQuicStream(QuicStreamId id,
14 QuicSession* session)
15 : sequencer_(this),
16 id_(id),
17 offset_(0),
18 session_(session),
19 error_(QUIC_NO_ERROR),
20 read_side_closed_(false),
21 write_side_closed_(false) {
22 }
23
24 ReliableQuicStream::~ReliableQuicStream() {
25 }
26
27 bool ReliableQuicStream::WillAcceptStreamFrame(
28 const QuicStreamFrame& frame) const {
29 if (read_side_closed_) {
30 return false;
31 }
32 if (frame.stream_id != id_) {
33 LOG(ERROR) << "Error!";
34 return false;
35 }
36 return sequencer_.WillAcceptStreamFrame(frame);
37 }
38
39 bool ReliableQuicStream::OnStreamFrame(const QuicStreamFrame& frame) {
40 DCHECK_EQ(frame.stream_id, id_);
41 if (read_side_closed_) {
42 // This can only happen if a client sends data after sending a fin or stream
43 // reset.
44 Close(QUIC_STREAM_DATA_AFTER_TERMINATION);
45 return false;
46 }
47
48 bool accepted = sequencer_.OnStreamFrame(frame);
49
50 if (frame.fin) {
51 sequencer_.CloseStreamAtOffset(frame.offset + frame.data.size(),
52 true);
53 }
54
55 return accepted;
56 }
57
58 void ReliableQuicStream::OnStreamReset(QuicErrorCode error,
59 QuicStreamOffset offset) {
60 error_ = error;
61 sequencer_.CloseStreamAtOffset(offset, false); // Full close
jar 2012/11/01 22:21:10 nit: period at end
Ryan Hamilton 2012/11/01 22:52:20 Fixed upstream.
62 }
63
64 void ReliableQuicStream::ConnectionClose(QuicErrorCode error, bool from_peer) {
65 error_ = error;
66 if (from_peer) {
67 TerminateFromPeer(false);
68 } else {
69 CloseWriteSide();
70 CloseReadSide();
71 }
72 }
73
74 void ReliableQuicStream::TerminateFromPeer(bool half_close) {
75 if (!half_close) {
76 CloseWriteSide();
77 }
78 CloseReadSide();
79 }
80
81 void ReliableQuicStream::Close(QuicErrorCode error) {
82 error_ = error;
83 session()->SendRstStream(id(), error, offset_);
84 }
85
86 int ReliableQuicStream::Readv(const struct iovec* iov, int iov_len) {
87 return sequencer_.Readv(iov, iov_len);
88 }
89
90 bool ReliableQuicStream::IsHalfClosed() {
91 return sequencer_.IsHalfClosed();
92 }
93
94 bool ReliableQuicStream::HasBytesToRead() {
95 return sequencer_.HasBytesToRead();
96 }
97
98 ssize_t ReliableQuicStream::WriteData(StringPiece data, bool fin) {
99 if (write_side_closed_) {
100 DLOG(ERROR) << "Attempt to write when the write side is closed";
101 return 0;
102 }
103
104 session()->WriteData(id(), data, offset_, fin);
105 offset_ += data.length();
106 if (fin) {
107 CloseWriteSide();
108 }
109 return data.length();
110 }
111
112 void ReliableQuicStream::CloseReadSide() {
113 DLOG(INFO) << "Done reading from stream " << id();
114
115 read_side_closed_ = true;
116 if (write_side_closed_) {
117 session_->CloseStream(id());
118 }
119 }
120
121 void ReliableQuicStream::CloseWriteSide() {
122 DLOG(INFO) << "Done writing to stream " << id();
123
124 write_side_closed_ = true;
125 if (read_side_closed_) {
126 session_->CloseStream(id());
127 }
128 }
129
130 } // namespace net
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 1275:d14800f88434