mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Prevent logging connection failure when mDNS client connects to test the connection.
PiperOrigin-RevId: 850545490
This commit is contained in:
committed by
Copybara-Service
parent
c86f9f573f
commit
931624a621
@@ -32,6 +32,7 @@ struct Exception {
|
||||
kTimeout = 5, // Operation did not finish within specified time.
|
||||
kIllegalCharacters = 6, // File name or parent path contained
|
||||
// illegal chars
|
||||
kNoData = 7, // No data available.
|
||||
};
|
||||
bool Ok() const { return value == kSuccess; }
|
||||
explicit operator bool() const { return Ok(); }
|
||||
|
||||
@@ -182,9 +182,11 @@ ExceptionOr<ByteArray> NearbyClientSocket::Read(std::int64_t size) {
|
||||
// Successfully read some bytes.
|
||||
total_bytes_read += bytes_read;
|
||||
} else if (bytes_read == 0) {
|
||||
// The peer has performed a graceful shutdown.
|
||||
LOG(INFO) << "Socket closed gracefully by peer before all data was read.";
|
||||
return {Exception::kIo};
|
||||
// The peer has performed a graceful shutdown. Return any data already
|
||||
// read.
|
||||
buffer.resize(total_bytes_read);
|
||||
LOG(INFO) << "Socket closed by peer, data size: " << buffer.size();
|
||||
return ExceptionOr(ByteArray(std::move(buffer)));
|
||||
} else { // bytes_read == SOCKET_ERROR
|
||||
if (WSAGetLastError() == WSAEINTR) {
|
||||
VLOG(1) << "Interrupted while reading from socket.";
|
||||
|
||||
@@ -210,14 +210,13 @@ ServiceAddress SocketAddress::ToServiceAddress(uint16_t port) const {
|
||||
ipv4_address()->sin_addr.S_un.S_un_b.s_b4},
|
||||
.port = port,
|
||||
};
|
||||
} else {
|
||||
return ServiceAddress{
|
||||
.address =
|
||||
std::vector<char>(ipv6_address()->sin6_addr.u.Byte,
|
||||
ipv6_address()->sin6_addr.u.Byte + 16),
|
||||
.port = port,
|
||||
};
|
||||
}
|
||||
return ServiceAddress{
|
||||
.address =
|
||||
std::vector<char>(ipv6_address()->sin6_addr.u.Byte,
|
||||
ipv6_address()->sin6_addr.u.Byte + 16),
|
||||
.port = port,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
|
||||
#include "internal/platform/byte_array.h"
|
||||
@@ -56,7 +55,7 @@ ExceptionOr<ByteArray> InputStream::ReadExactly(std::size_t size) {
|
||||
const ByteArray& result = read_bytes.result();
|
||||
|
||||
if (result.Empty()) {
|
||||
return ExceptionOr<ByteArray>(Exception::kIo);
|
||||
return ExceptionOr<ByteArray>(Exception::kNoData);
|
||||
}
|
||||
if (current_pos == 0) {
|
||||
if (result.size() == size) {
|
||||
|
||||
Reference in New Issue
Block a user