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/quic_reliable_client_stream.h" 6 7 #include "net/base/net_errors.h" 8 #include "net/quic/quic_session.h" 9 10 namespace net { 11 12 QuicReliableClientStream::QuicReliableClientStream(QuicStreamId id, 13 QuicSession* session, 14 const BoundNetLog& net_log) 15 : ReliableQuicStream(id, session), 16 net_log_(net_log), 17 delegate_(NULL) { 18 } 19 20 QuicReliableClientStream::~QuicReliableClientStream() { 21 if (delegate_) 22 delegate_->OnClose(connection_error()); 23 } 24 25 uint32 QuicReliableClientStream::ProcessData(const char* data, 26 uint32 data_len) { 27 // TODO(rch): buffer data if we don't have a delegate. 28 if (!delegate_) 29 return ERR_ABORTED; 30 31 int rv = delegate_->OnDataReceived(data, data_len); 32 if (rv != OK) { 33 DLOG(ERROR) << "Delegate refused data, rv: " << rv; 34 Close(QUIC_BAD_APPLICATION_PAYLOAD); 35 return 0; 36 } 37 return data_len; 38 } 39 40 void QuicReliableClientStream::TerminateFromPeer(bool half_close) { 41 if (delegate_) { 42 delegate_->OnClose(connection_error()); 43 delegate_ = NULL; 44 } 45 ReliableQuicStream::TerminateFromPeer(half_close); 46 } 47 48 void QuicReliableClientStream::SetDelegate( 49 QuicReliableClientStream::Delegate* delegate) { 50 DCHECK((!delegate_ && delegate) || (delegate_ && !delegate)); 51 delegate_ = delegate; 52 } 53 54 void QuicReliableClientStream::OnError(int error) { 55 if (delegate_) { 56 QuicReliableClientStream::Delegate* delegate = delegate_; 57 delegate_ = NULL; 58 delegate->OnError(error); 59 } 60 } 61 62 } // namespace net 63