summaryrefslogtreecommitdiff
path: root/chromium/net/tools/quic/quic_simple_per_connection_packet_writer.cc
blob: 9046a9b7b8876b8b4aca2bad86ad4882b7e3b20b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/tools/quic/quic_simple_per_connection_packet_writer.h"

#include "base/bind.h"
#include "net/tools/quic/quic_simple_server_packet_writer.h"

namespace net {

QuicSimplePerConnectionPacketWriter::QuicSimplePerConnectionPacketWriter(
    QuicSimpleServerPacketWriter* shared_writer)
    : shared_writer_(shared_writer),
      connection_(nullptr),
      weak_factory_(this) {}

QuicSimplePerConnectionPacketWriter::~QuicSimplePerConnectionPacketWriter() =
    default;

QuicPacketWriter* QuicSimplePerConnectionPacketWriter::shared_writer() const {
  return shared_writer_;
}

WriteResult QuicSimplePerConnectionPacketWriter::WritePacket(
    const char* buffer,
    size_t buf_len,
    const QuicIpAddress& self_address,
    const QuicSocketAddress& peer_address,
    PerPacketOptions* options) {
  return shared_writer_->WritePacketWithCallback(
      buffer, buf_len, self_address, peer_address, options,
      base::Bind(&QuicSimplePerConnectionPacketWriter::OnWriteComplete,
                 weak_factory_.GetWeakPtr()));
}

bool QuicSimplePerConnectionPacketWriter::IsWriteBlockedDataBuffered() const {
  return shared_writer_->IsWriteBlockedDataBuffered();
}

bool QuicSimplePerConnectionPacketWriter::IsWriteBlocked() const {
  return shared_writer_->IsWriteBlocked();
}

void QuicSimplePerConnectionPacketWriter::SetWritable() {
  shared_writer_->SetWritable();
}

void QuicSimplePerConnectionPacketWriter::OnWriteComplete(WriteResult result) {
  if (connection_ && result.status == WRITE_STATUS_ERROR) {
    connection_->OnWriteError(result.error_code);
  }
}

QuicByteCount QuicSimplePerConnectionPacketWriter::GetMaxPacketSize(
    const QuicSocketAddress& peer_address) const {
  return shared_writer_->GetMaxPacketSize(peer_address);
}

}  // namespace net