mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Add InputStream::ReadExactly
Read() can return fewer bytes than requested. ReadExactly() will call Read() repeatedly until we have read as many bytes as we need. PiperOrigin-RevId: 518719418
This commit is contained in:
committed by
Copybara-Service
parent
ebf87cc581
commit
1a78b33a89
@@ -102,7 +102,7 @@ void Medium::RunLoop(BluetoothSocket socket) {
|
||||
NEARBY_LOGS(INFO) << "Run loop";
|
||||
InputStream& input = socket.GetInputStream();
|
||||
while (!cancellation_flag_.Cancelled()) {
|
||||
ExceptionOr<ByteArray> header = input.Read(kHeaderSize);
|
||||
ExceptionOr<ByteArray> header = input.ReadExactly(kHeaderSize);
|
||||
if (!header.ok() || header.result().size() != kHeaderSize) {
|
||||
break;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ void Medium::RunLoop(BluetoothSocket socket) {
|
||||
static_cast<unsigned int>(data[3]);
|
||||
ExceptionOr<ByteArray> payload;
|
||||
if (length > 0) {
|
||||
payload = input.Read(length);
|
||||
payload = input.ReadExactly(length);
|
||||
} else {
|
||||
payload = ExceptionOr<ByteArray>(ByteArray(""));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user