OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 #ifndef BLIMP_NET_COMPRESSED_PACKET_WRITER_H_ | |
6 #define BLIMP_NET_COMPRESSED_PACKET_WRITER_H_ | |
7 | |
8 #include "base/memory/weak_ptr.h" | |
9 #include "blimp/net/blimp_net_export.h" | |
10 #include "blimp/net/packet_writer.h" | |
11 #include "net/base/completion_callback.h" | |
12 #include "net/base/io_buffer.h" | |
13 #include "third_party/zlib/zlib.h" | |
14 | |
15 namespace blimp { | |
16 | |
17 // Filter object which wraps a PacketWriter, adding a DEFLATE compression step | |
18 // to outgoing packets. | |
19 // | |
20 // Each packet is appended as a DEFLATE block to a long-lived compression | |
21 // stream. | |
22 // Each block is prefixed with a 32-bit word representing the length of the | |
23 // decompressed payload, used for sizing output buffers. | |
Wez
2016/03/29 21:38:38
Looks like you got rid of that in the latest patch
Kevin M
2016/03/29 23:48:24
Done.
| |
24 // Blocks are explicitly flushed at each packet boundary, which prevents zlib's | |
25 // internal buffers from introducing unwanted output latency. | |
26 // Gzip headers and CRC checks are omitted from the stream output. | |
27 class BLIMP_NET_EXPORT CompressedPacketWriter : public PacketWriter { | |
28 public: | |
29 // |source|: The PacketWriter which will receive compressed packets. | |
30 explicit CompressedPacketWriter(scoped_ptr<PacketWriter> sink); | |
31 ~CompressedPacketWriter() override; | |
32 | |
33 // PacketWriter implementation. | |
34 void WritePacket(const scoped_refptr<net::DrainableIOBuffer>& buf, | |
35 const net::CompletionCallback& cb) override; | |
36 | |
37 private: | |
38 // Compresses |src_buf| into |dest_buf|, and sets |compressed_size| with the | |
Wez
2016/03/29 21:38:38
There is no |compressed_size| - you mean it return
Kevin M
2016/03/29 23:48:24
Done.
| |
39 // length of the compressed packet (including decompressed length). | |
Wez
2016/03/29 21:38:38
Not sure what "including decompressed length means
Kevin M
2016/03/29 23:48:24
I meant "decompressed length header." But that's N
| |
40 // On success, returns a >= 0 value indicating the size of the | |
41 // compressed payload. | |
42 // On failure, returns a negative value indicating the error code | |
43 // (see net_errors.h). | |
44 int Compress(const scoped_refptr<net::DrainableIOBuffer>& src_buf, | |
45 const scoped_refptr<net::GrowableIOBuffer>& dest_buf); | |
46 | |
47 z_stream zlib_stream_{}; | |
48 scoped_ptr<PacketWriter> sink_; | |
49 scoped_refptr<net::GrowableIOBuffer> compressed_buf_; | |
50 size_t uncompressed_size_total_ = 0; | |
Wez
2016/03/29 21:38:38
nit: Do these need to be unsigned literals?
Kevin M
2016/03/29 23:48:24
Done.
Kevin M
2016/03/29 23:48:24
Done.
| |
51 size_t compressed_size_total_ = 0; | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(CompressedPacketWriter); | |
54 }; | |
55 | |
56 } // namespace blimp | |
57 | |
58 #endif // BLIMP_NET_COMPRESSED_PACKET_WRITER_H_ | |
OLD | NEW |