mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-15 07:06:11 -04:00
Fixed bug of folder sharing
PiperOrigin-RevId: 524417795
This commit is contained in:
committed by
Copybara-Service
parent
6dac39292b
commit
49aa73bbdd
@@ -156,12 +156,18 @@ BluetoothSocket::BluetoothInputStream::BluetoothInputStream(
|
||||
ExceptionOr<ByteArray> BluetoothSocket::BluetoothInputStream::Read(
|
||||
std::int64_t size) {
|
||||
try {
|
||||
if (size <= 0 || size > kMaxTransmitPacketSize) {
|
||||
if (size <= 0) {
|
||||
NEARBY_LOGS(ERROR) << __func__
|
||||
<< ": Invalid transmit packet size: " << size;
|
||||
return {Exception::kIo};
|
||||
}
|
||||
|
||||
if (size > read_buffer_.Capacity()) {
|
||||
NEARBY_LOGS(WARNING) << __func__
|
||||
<< ": resize receive buffer to packet size: " << size;
|
||||
read_buffer_ = Buffer(size);
|
||||
}
|
||||
|
||||
// Init the read buffer.
|
||||
read_buffer_.Length(0);
|
||||
|
||||
@@ -223,10 +229,11 @@ BluetoothSocket::BluetoothOutputStream::BluetoothOutputStream(
|
||||
|
||||
Exception BluetoothSocket::BluetoothOutputStream::Write(const ByteArray& data) {
|
||||
try {
|
||||
if (data.size() > kMaxTransmitPacketSize) {
|
||||
NEARBY_LOGS(ERROR) << __func__ << ": Transmit packet size " << data.size()
|
||||
<< " is too big.";
|
||||
return {Exception::kIo};
|
||||
if (data.size() > write_buffer_.Capacity()) {
|
||||
NEARBY_LOGS(WARNING) << __func__
|
||||
<< ": resize write buffer to packet size: "
|
||||
<< data.size();
|
||||
write_buffer_ = Buffer(data.size());
|
||||
}
|
||||
|
||||
std::memcpy(write_buffer_.data(), data.data(), data.size());
|
||||
|
||||
@@ -101,7 +101,7 @@ class BluetoothSocket : public api::BluetoothSocket {
|
||||
IAsyncAction CancelIOAsync();
|
||||
|
||||
private:
|
||||
static constexpr int kMaxTransmitPacketSize = 4096;
|
||||
static constexpr int kInitialTransmitPacketSize = 4096;
|
||||
|
||||
class BluetoothInputStream : public InputStream {
|
||||
public:
|
||||
@@ -113,7 +113,7 @@ class BluetoothSocket : public api::BluetoothSocket {
|
||||
|
||||
private:
|
||||
IInputStream winrt_input_stream_{nullptr};
|
||||
Buffer read_buffer_{kMaxTransmitPacketSize};
|
||||
Buffer read_buffer_{kInitialTransmitPacketSize};
|
||||
};
|
||||
|
||||
class BluetoothOutputStream : public OutputStream {
|
||||
@@ -128,11 +128,11 @@ class BluetoothSocket : public api::BluetoothSocket {
|
||||
|
||||
private:
|
||||
IOutputStream winrt_output_stream_{nullptr};
|
||||
Buffer write_buffer_{kMaxTransmitPacketSize};
|
||||
Buffer write_buffer_{kInitialTransmitPacketSize};
|
||||
};
|
||||
|
||||
bool InternalConnect(HostName connectionHostName,
|
||||
winrt::hstring connectionServiceName);
|
||||
winrt::hstring connectionServiceName);
|
||||
|
||||
winrt::fire_and_forget Listener_ConnectionStatusChanged(
|
||||
winrt::Windows::Devices::Bluetooth::BluetoothDevice device,
|
||||
|
||||
Reference in New Issue
Block a user