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