This source file includes following definitions.
- delegate_
- ProcessData
- OnFinRead
- OnCanWrite
- EffectivePriority
- WriteStreamData
- SetDelegate
- OnError
- CanWrite
#include "net/quic/quic_reliable_client_stream.h"
#include "base/callback_helpers.h"
#include "net/base/net_errors.h"
#include "net/quic/quic_session.h"
#include "net/quic/quic_write_blocked_list.h"
namespace net {
QuicReliableClientStream::QuicReliableClientStream(QuicStreamId id,
QuicSession* session,
const BoundNetLog& net_log)
: QuicDataStream(id, session),
net_log_(net_log),
delegate_(NULL) {
}
QuicReliableClientStream::~QuicReliableClientStream() {
if (delegate_)
delegate_->OnClose(connection_error());
}
uint32 QuicReliableClientStream::ProcessData(const char* data,
uint32 data_len) {
if (!delegate_)
return ERR_ABORTED;
int rv = delegate_->OnDataReceived(data, data_len);
if (rv != OK) {
DLOG(ERROR) << "Delegate refused data, rv: " << rv;
Reset(QUIC_BAD_APPLICATION_PAYLOAD);
return 0;
}
return data_len;
}
void QuicReliableClientStream::OnFinRead() {
if (delegate_) {
delegate_->OnClose(connection_error());
delegate_ = NULL;
}
ReliableQuicStream::OnFinRead();
}
void QuicReliableClientStream::OnCanWrite() {
ReliableQuicStream::OnCanWrite();
if (!HasBufferedData() && !callback_.is_null()) {
base::ResetAndReturn(&callback_).Run(OK);
}
}
QuicPriority QuicReliableClientStream::EffectivePriority() const {
if (delegate_ && delegate_->HasSendHeadersComplete()) {
return QuicDataStream::EffectivePriority();
}
return QuicWriteBlockedList::kHighestPriority;
}
int QuicReliableClientStream::WriteStreamData(
base::StringPiece data,
bool fin,
const CompletionCallback& callback) {
DCHECK(!HasBufferedData());
WriteOrBufferData(data, fin, NULL);
if (!HasBufferedData()) {
return OK;
}
callback_ = callback;
return ERR_IO_PENDING;
}
void QuicReliableClientStream::SetDelegate(
QuicReliableClientStream::Delegate* delegate) {
DCHECK((!delegate_ && delegate) || (delegate_ && !delegate));
delegate_ = delegate;
}
void QuicReliableClientStream::OnError(int error) {
if (delegate_) {
QuicReliableClientStream::Delegate* delegate = delegate_;
delegate_ = NULL;
delegate->OnError(error);
}
}
bool QuicReliableClientStream::CanWrite(const CompletionCallback& callback) {
bool can_write = session()->connection()->CanWrite(
NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA,
id() == kCryptoStreamId ? IS_HANDSHAKE : NOT_HANDSHAKE);
if (!can_write) {
session()->MarkWriteBlocked(id(), EffectivePriority());
DCHECK(callback_.is_null());
callback_ = callback;
}
return can_write;
}
}