Merge changes I90e10c74,I038d1df4,I4299bd96 am: 73d44bb6c2
am: 72138abaa7
Change-Id: Ifa3354b755dab76cff00f3e7ceb0a80e5dd6657d
This commit is contained in:
commit
d6998c98d8
4 changed files with 44 additions and 45 deletions
|
@ -317,8 +317,8 @@ cc_binary_host {
|
|||
static_libs: [
|
||||
"libadb_crypto",
|
||||
"libadb_host",
|
||||
"libadb_pairing_auth",
|
||||
"libadb_pairing_connection",
|
||||
"libadb_pairing_auth",
|
||||
"libadb_pairing_connection",
|
||||
"libadb_protos",
|
||||
"libadb_tls_connection",
|
||||
"libandroidfw",
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
#include "adb_client.h"
|
||||
#include "adb_io.h"
|
||||
#include "adb_utils.h"
|
||||
#include "brotli_utils.h"
|
||||
#include "compression_utils.h"
|
||||
#include "file_sync_protocol.h"
|
||||
#include "line_printer.h"
|
||||
#include "sysdeps/errno.h"
|
||||
|
@ -580,8 +580,8 @@ class SyncConnection {
|
|||
|
||||
while (true) {
|
||||
Block output;
|
||||
BrotliEncodeResult result = encoder.Encode(&output);
|
||||
if (result == BrotliEncodeResult::Error) {
|
||||
EncodeResult result = encoder.Encode(&output);
|
||||
if (result == EncodeResult::Error) {
|
||||
Error("compressing '%s' locally failed", lpath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
@ -592,12 +592,12 @@ class SyncConnection {
|
|||
WriteOrDie(lpath, rpath, &sbuf, sizeof(SyncRequest) + output.size());
|
||||
}
|
||||
|
||||
if (result == BrotliEncodeResult::Done) {
|
||||
if (result == EncodeResult::Done) {
|
||||
sending = false;
|
||||
break;
|
||||
} else if (result == BrotliEncodeResult::NeedInput) {
|
||||
} else if (result == EncodeResult::NeedInput) {
|
||||
break;
|
||||
} else if (result == BrotliEncodeResult::MoreOutput) {
|
||||
} else if (result == EncodeResult::MoreOutput) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -1076,9 +1076,9 @@ static bool sync_recv_v2(SyncConnection& sc, const char* rpath, const char* lpat
|
|||
|
||||
while (true) {
|
||||
std::span<char> output;
|
||||
BrotliDecodeResult result = decoder.Decode(&output);
|
||||
DecodeResult result = decoder.Decode(&output);
|
||||
|
||||
if (result == BrotliDecodeResult::Error) {
|
||||
if (result == DecodeResult::Error) {
|
||||
sc.Error("decompress failed");
|
||||
adb_unlink(lpath);
|
||||
return false;
|
||||
|
@ -1097,15 +1097,15 @@ static bool sync_recv_v2(SyncConnection& sc, const char* rpath, const char* lpat
|
|||
sc.RecordBytesTransferred(msg.data.size);
|
||||
sc.ReportProgress(name != nullptr ? name : rpath, bytes_copied, expected_size);
|
||||
|
||||
if (result == BrotliDecodeResult::NeedInput) {
|
||||
if (result == DecodeResult::NeedInput) {
|
||||
break;
|
||||
} else if (result == BrotliDecodeResult::MoreOutput) {
|
||||
} else if (result == DecodeResult::MoreOutput) {
|
||||
continue;
|
||||
} else if (result == BrotliDecodeResult::Done) {
|
||||
} else if (result == DecodeResult::Done) {
|
||||
reading = false;
|
||||
break;
|
||||
} else {
|
||||
LOG(FATAL) << "invalid BrotliDecodeResult: " << static_cast<int>(result);
|
||||
LOG(FATAL) << "invalid DecodeResult: " << static_cast<int>(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,14 @@
|
|||
|
||||
#include "types.h"
|
||||
|
||||
enum class BrotliDecodeResult {
|
||||
enum class DecodeResult {
|
||||
Error,
|
||||
Done,
|
||||
NeedInput,
|
||||
MoreOutput,
|
||||
};
|
||||
|
||||
enum class EncodeResult {
|
||||
Error,
|
||||
Done,
|
||||
NeedInput,
|
||||
|
@ -38,7 +45,7 @@ struct BrotliDecoder {
|
|||
|
||||
void Append(Block&& block) { input_buffer_.append(std::move(block)); }
|
||||
|
||||
BrotliDecodeResult Decode(std::span<char>* output) {
|
||||
DecodeResult Decode(std::span<char>* output) {
|
||||
size_t available_in = input_buffer_.front_size();
|
||||
const uint8_t* next_in = reinterpret_cast<const uint8_t*>(input_buffer_.front_data());
|
||||
|
||||
|
@ -56,16 +63,16 @@ struct BrotliDecoder {
|
|||
|
||||
switch (r) {
|
||||
case BROTLI_DECODER_RESULT_SUCCESS:
|
||||
return BrotliDecodeResult::Done;
|
||||
return DecodeResult::Done;
|
||||
case BROTLI_DECODER_RESULT_ERROR:
|
||||
return BrotliDecodeResult::Error;
|
||||
return DecodeResult::Error;
|
||||
case BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:
|
||||
// Brotli guarantees as one of its invariants that if it returns NEEDS_MORE_INPUT,
|
||||
// it will consume the entire input buffer passed in, so we don't have to worry
|
||||
// about bytes left over in the front block with more input remaining.
|
||||
return BrotliDecodeResult::NeedInput;
|
||||
return DecodeResult::NeedInput;
|
||||
case BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:
|
||||
return BrotliDecodeResult::MoreOutput;
|
||||
return DecodeResult::MoreOutput;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,13 +82,6 @@ struct BrotliDecoder {
|
|||
std::unique_ptr<BrotliDecoderState, void (*)(BrotliDecoderState*)> decoder_;
|
||||
};
|
||||
|
||||
enum class BrotliEncodeResult {
|
||||
Error,
|
||||
Done,
|
||||
NeedInput,
|
||||
MoreOutput,
|
||||
};
|
||||
|
||||
template <size_t OutputBlockSize>
|
||||
struct BrotliEncoder {
|
||||
explicit BrotliEncoder()
|
||||
|
@ -95,7 +95,7 @@ struct BrotliEncoder {
|
|||
void Append(Block input) { input_buffer_.append(std::move(input)); }
|
||||
void Finish() { finished_ = true; }
|
||||
|
||||
BrotliEncodeResult Encode(Block* output) {
|
||||
EncodeResult Encode(Block* output) {
|
||||
output->clear();
|
||||
while (true) {
|
||||
size_t available_in = input_buffer_.front_size();
|
||||
|
@ -112,7 +112,7 @@ struct BrotliEncoder {
|
|||
|
||||
if (!BrotliEncoderCompressStream(encoder_.get(), op, &available_in, &next_in,
|
||||
&available_out, &next_out, nullptr)) {
|
||||
return BrotliEncodeResult::Error;
|
||||
return EncodeResult::Error;
|
||||
}
|
||||
|
||||
size_t bytes_consumed = input_buffer_.front_size() - available_in;
|
||||
|
@ -123,14 +123,14 @@ struct BrotliEncoder {
|
|||
if (BrotliEncoderIsFinished(encoder_.get())) {
|
||||
output_block_.resize(OutputBlockSize - output_bytes_left_);
|
||||
*output = std::move(output_block_);
|
||||
return BrotliEncodeResult::Done;
|
||||
return EncodeResult::Done;
|
||||
} else if (output_bytes_left_ == 0) {
|
||||
*output = std::move(output_block_);
|
||||
output_block_.resize(OutputBlockSize);
|
||||
output_bytes_left_ = OutputBlockSize;
|
||||
return BrotliEncodeResult::MoreOutput;
|
||||
return EncodeResult::MoreOutput;
|
||||
} else if (input_buffer_.empty()) {
|
||||
return BrotliEncodeResult::NeedInput;
|
||||
return EncodeResult::NeedInput;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -57,7 +57,7 @@
|
|||
#include "adb_io.h"
|
||||
#include "adb_trace.h"
|
||||
#include "adb_utils.h"
|
||||
#include "brotli_utils.h"
|
||||
#include "compression_utils.h"
|
||||
#include "file_sync_protocol.h"
|
||||
#include "security_log_tags.h"
|
||||
#include "sysdeps/errno.h"
|
||||
|
@ -288,8 +288,8 @@ static bool handle_send_file_compressed(borrowed_fd s, unique_fd fd, uint32_t* t
|
|||
|
||||
while (true) {
|
||||
std::span<char> output;
|
||||
BrotliDecodeResult result = decoder.Decode(&output);
|
||||
if (result == BrotliDecodeResult::Error) {
|
||||
DecodeResult result = decoder.Decode(&output);
|
||||
if (result == DecodeResult::Error) {
|
||||
SendSyncFailErrno(s, "decompress failed");
|
||||
return false;
|
||||
}
|
||||
|
@ -299,14 +299,14 @@ static bool handle_send_file_compressed(borrowed_fd s, unique_fd fd, uint32_t* t
|
|||
return false;
|
||||
}
|
||||
|
||||
if (result == BrotliDecodeResult::NeedInput) {
|
||||
if (result == DecodeResult::NeedInput) {
|
||||
break;
|
||||
} else if (result == BrotliDecodeResult::MoreOutput) {
|
||||
} else if (result == DecodeResult::MoreOutput) {
|
||||
continue;
|
||||
} else if (result == BrotliDecodeResult::Done) {
|
||||
} else if (result == DecodeResult::Done) {
|
||||
break;
|
||||
} else {
|
||||
LOG(FATAL) << "invalid BrotliDecodeResult: " << static_cast<int>(result);
|
||||
LOG(FATAL) << "invalid DecodeResult: " << static_cast<int>(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -591,7 +591,6 @@ static bool do_send_v2(int s, const std::string& path, std::vector<char>& buffer
|
|||
static bool recv_uncompressed(borrowed_fd s, unique_fd fd, std::vector<char>& buffer) {
|
||||
syncmsg msg;
|
||||
msg.data.id = ID_DATA;
|
||||
std::optional<BrotliEncoder<SYNC_DATA_MAX>> encoder;
|
||||
while (true) {
|
||||
int r = adb_read(fd.get(), &buffer[0], buffer.size() - sizeof(msg.data));
|
||||
if (r <= 0) {
|
||||
|
@ -633,8 +632,8 @@ static bool recv_compressed(borrowed_fd s, unique_fd fd) {
|
|||
|
||||
while (true) {
|
||||
Block output;
|
||||
BrotliEncodeResult result = encoder.Encode(&output);
|
||||
if (result == BrotliEncodeResult::Error) {
|
||||
EncodeResult result = encoder.Encode(&output);
|
||||
if (result == EncodeResult::Error) {
|
||||
SendSyncFailErrno(s, "compress failed");
|
||||
return false;
|
||||
}
|
||||
|
@ -647,12 +646,12 @@ static bool recv_compressed(borrowed_fd s, unique_fd fd) {
|
|||
}
|
||||
}
|
||||
|
||||
if (result == BrotliEncodeResult::Done) {
|
||||
if (result == EncodeResult::Done) {
|
||||
sending = false;
|
||||
break;
|
||||
} else if (result == BrotliEncodeResult::NeedInput) {
|
||||
} else if (result == EncodeResult::NeedInput) {
|
||||
break;
|
||||
} else if (result == BrotliEncodeResult::MoreOutput) {
|
||||
} else if (result == EncodeResult::MoreOutput) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue