| Index: blimp/net/compressed_packet_writer.h
|
| diff --git a/blimp/net/compressed_packet_writer.h b/blimp/net/compressed_packet_writer.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..78f4472f4a99327b14ebfb49fa1f3de645f37110
|
| --- /dev/null
|
| +++ b/blimp/net/compressed_packet_writer.h
|
| @@ -0,0 +1,56 @@
|
| +// Copyright 2016 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.
|
| +
|
| +#ifndef BLIMP_NET_COMPRESSED_PACKET_WRITER_H_
|
| +#define BLIMP_NET_COMPRESSED_PACKET_WRITER_H_
|
| +
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "blimp/net/blimp_net_export.h"
|
| +#include "blimp/net/packet_writer.h"
|
| +#include "net/base/completion_callback.h"
|
| +#include "net/base/io_buffer.h"
|
| +#include "third_party/zlib/zlib.h"
|
| +
|
| +namespace blimp {
|
| +
|
| +// Filter object which wraps a PacketWriter, adding a DEFLATE compression step
|
| +// to outgoing packets.
|
| +//
|
| +// Each packet is appended as a DEFLATE block to a long-lived compression
|
| +// stream.
|
| +// Each block is prefixed with a 32-bit word representing the length of the
|
| +// decompressed payload, used for sizing output buffers.
|
| +// Blocks are explicitly flushed at each packet boundary, which prevents zlib's
|
| +// internal buffers from introducing unwanted output latency.
|
| +// Gzip headers and CRC checks are omitted from the stream output.
|
| +class BLIMP_NET_EXPORT CompressedPacketWriter : public PacketWriter {
|
| + public:
|
| + // |source|: The PacketWriter which will receive compressed packets.
|
| + explicit CompressedPacketWriter(scoped_ptr<PacketWriter> sink);
|
| + ~CompressedPacketWriter() override;
|
| +
|
| + // PacketWriter implementation.
|
| + void WritePacket(const scoped_refptr<net::DrainableIOBuffer>& buf,
|
| + const net::CompletionCallback& cb) override;
|
| +
|
| + private:
|
| + // Compresses |src_buf| into |dest_buf|, and sets |compressed_size| with the
|
| + // length of the compressed packet (including decompressed length).
|
| + // Returns true if compression completed successfully.
|
| + bool Compress(const scoped_refptr<net::DrainableIOBuffer>& src_buf,
|
| + const scoped_refptr<net::GrowableIOBuffer>& dest_buf,
|
| + size_t* compressed_size);
|
| +
|
| + z_stream zlib_stream_;
|
| + scoped_ptr<PacketWriter> sink_;
|
| + scoped_refptr<net::GrowableIOBuffer> compressed_buf_;
|
| + size_t uncompressed_size_total_ = 0;
|
| + size_t compressed_size_total_ = 0;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(CompressedPacketWriter);
|
| +};
|
| +
|
| +} // namespace blimp
|
| +
|
| +#endif // BLIMP_NET_COMPRESSED_PACKET_WRITER_H_
|
|
|