1 // Copyright 2014 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_per_connection_packet_writer.h"
6
7 #include "net/quic/quic_server_packet_writer.h"
8
9 namespace net {
10
QuicPerConnectionPacketWriter(QuicServerPacketWriter * shared_writer,QuicConnection * connection)11 QuicPerConnectionPacketWriter::QuicPerConnectionPacketWriter(
12 QuicServerPacketWriter* shared_writer,
13 QuicConnection* connection)
14 : shared_writer_(shared_writer),
15 connection_(connection),
16 weak_factory_(this){
17 }
18
~QuicPerConnectionPacketWriter()19 QuicPerConnectionPacketWriter::~QuicPerConnectionPacketWriter() {
20 }
21
shared_writer() const22 QuicPacketWriter* QuicPerConnectionPacketWriter::shared_writer() const {
23 return shared_writer_;
24 }
25
WritePacket(const char * buffer,size_t buf_len,const IPAddressNumber & self_address,const IPEndPoint & peer_address)26 WriteResult QuicPerConnectionPacketWriter::WritePacket(
27 const char* buffer,
28 size_t buf_len,
29 const IPAddressNumber& self_address,
30 const IPEndPoint& peer_address) {
31 return shared_writer_->WritePacketWithCallback(
32 buffer,
33 buf_len,
34 self_address,
35 peer_address,
36 base::Bind(&QuicPerConnectionPacketWriter::OnWriteComplete,
37 weak_factory_.GetWeakPtr()));
38 }
39
IsWriteBlockedDataBuffered() const40 bool QuicPerConnectionPacketWriter::IsWriteBlockedDataBuffered() const {
41 return shared_writer_->IsWriteBlockedDataBuffered();
42 }
43
IsWriteBlocked() const44 bool QuicPerConnectionPacketWriter::IsWriteBlocked() const {
45 return shared_writer_->IsWriteBlocked();
46 }
47
SetWritable()48 void QuicPerConnectionPacketWriter::SetWritable() {
49 shared_writer_->SetWritable();
50 }
51
OnWriteComplete(WriteResult result)52 void QuicPerConnectionPacketWriter::OnWriteComplete(WriteResult result) {
53 if (result.status == WRITE_STATUS_ERROR) {
54 connection_->OnWriteError(result.error_code);
55 }
56 }
57
58 } // namespace net
59