OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/quic/reliable_quic_stream.h" | 5 #include "net/quic/reliable_quic_stream.h" |
6 | 6 |
7 #include "net/quic/quic_session.h" | 7 #include "net/quic/quic_session.h" |
8 | 8 |
9 using base::StringPiece; | 9 using base::StringPiece; |
10 | 10 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 59 |
60 return accepted; | 60 return accepted; |
61 } | 61 } |
62 | 62 |
63 void ReliableQuicStream::OnStreamReset(QuicRstStreamErrorCode error) { | 63 void ReliableQuicStream::OnStreamReset(QuicRstStreamErrorCode error) { |
64 stream_error_ = error; | 64 stream_error_ = error; |
65 TerminateFromPeer(false); // Full close. | 65 TerminateFromPeer(false); // Full close. |
66 } | 66 } |
67 | 67 |
68 void ReliableQuicStream::ConnectionClose(QuicErrorCode error, bool from_peer) { | 68 void ReliableQuicStream::ConnectionClose(QuicErrorCode error, bool from_peer) { |
| 69 if (IsClosed()) { |
| 70 return; |
| 71 } |
69 if (error != QUIC_NO_ERROR) { | 72 if (error != QUIC_NO_ERROR) { |
70 stream_error_ = QUIC_STREAM_CONNECTION_ERROR; | 73 stream_error_ = QUIC_STREAM_CONNECTION_ERROR; |
71 connection_error_ = error; | 74 connection_error_ = error; |
72 } | 75 } |
73 | 76 |
74 if (from_peer) { | 77 if (from_peer) { |
75 TerminateFromPeer(false); | 78 TerminateFromPeer(false); |
76 } else { | 79 } else { |
77 CloseWriteSide(); | 80 CloseWriteSide(); |
78 CloseReadSide(); | 81 CloseReadSide(); |
79 } | 82 } |
80 } | 83 } |
81 | 84 |
82 void ReliableQuicStream::TerminateFromPeer(bool half_close) { | 85 void ReliableQuicStream::TerminateFromPeer(bool half_close) { |
83 if (!half_close) { | 86 if (!half_close) { |
84 CloseWriteSide(); | 87 CloseWriteSide(); |
85 } | 88 } |
86 CloseReadSide(); | 89 CloseReadSide(); |
87 } | 90 } |
88 | 91 |
89 void ReliableQuicStream::Close(QuicRstStreamErrorCode error) { | 92 void ReliableQuicStream::Close(QuicRstStreamErrorCode error) { |
90 stream_error_ = error; | 93 stream_error_ = error; |
91 session()->SendRstStream(id(), error); | 94 session()->SendRstStream(id(), error); |
92 } | 95 } |
93 | 96 |
94 bool ReliableQuicStream::IsHalfClosed() const { | 97 bool ReliableQuicStream::IsHalfClosed() const { |
95 return sequencer_.IsHalfClosed(); | 98 return sequencer_.IsHalfClosed(); |
96 } | 99 } |
97 | 100 |
| 101 bool ReliableQuicStream::IsClosed() const { |
| 102 return write_side_closed_ && (read_side_closed_ || IsHalfClosed()); |
| 103 } |
| 104 |
98 bool ReliableQuicStream::HasBytesToRead() const { | 105 bool ReliableQuicStream::HasBytesToRead() const { |
99 return sequencer_.HasBytesToRead(); | 106 return sequencer_.HasBytesToRead(); |
100 } | 107 } |
101 | 108 |
102 const IPEndPoint& ReliableQuicStream::GetPeerAddress() const { | 109 const IPEndPoint& ReliableQuicStream::GetPeerAddress() const { |
103 return session_->peer_address(); | 110 return session_->peer_address(); |
104 } | 111 } |
105 | 112 |
106 QuicConsumedData ReliableQuicStream::WriteData(StringPiece data, bool fin) { | 113 QuicConsumedData ReliableQuicStream::WriteData(StringPiece data, bool fin) { |
107 return WriteOrBuffer(data, fin); | 114 return WriteOrBuffer(data, fin); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 DLOG(INFO) << "Done writing to stream " << id(); | 195 DLOG(INFO) << "Done writing to stream " << id(); |
189 | 196 |
190 write_side_closed_ = true; | 197 write_side_closed_ = true; |
191 if (read_side_closed_) { | 198 if (read_side_closed_) { |
192 DLOG(INFO) << "Closing stream: " << id(); | 199 DLOG(INFO) << "Closing stream: " << id(); |
193 session_->CloseStream(id()); | 200 session_->CloseStream(id()); |
194 } | 201 } |
195 } | 202 } |
196 | 203 |
197 void ReliableQuicStream::OnClose() { | 204 void ReliableQuicStream::OnClose() { |
| 205 CloseReadSide(); |
| 206 CloseWriteSide(); |
| 207 |
198 if (visitor_) { | 208 if (visitor_) { |
199 Visitor* visitor = visitor_; | 209 Visitor* visitor = visitor_; |
200 // Calling Visitor::OnClose() may result the destruction of the visitor, | 210 // Calling Visitor::OnClose() may result the destruction of the visitor, |
201 // so we need to ensure we don't call it again. | 211 // so we need to ensure we don't call it again. |
202 visitor_ = NULL; | 212 visitor_ = NULL; |
203 visitor->OnClose(this); | 213 visitor->OnClose(this); |
204 } | 214 } |
205 } | 215 } |
206 | 216 |
207 } // namespace net | 217 } // namespace net |
OLD | NEW |