mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Avoid checking peer when getting streams from socket
PiperOrigin-RevId: 756403871
This commit is contained in:
committed by
Copybara-Service
parent
605f96a2d2
commit
f2ef072ac1
@@ -15,9 +15,13 @@
|
||||
#include "connections/implementation/ble_endpoint_channel.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "connections/implementation/base_endpoint_channel.h"
|
||||
#include "internal/platform/ble.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
@@ -25,12 +29,16 @@ namespace connections {
|
||||
namespace {
|
||||
|
||||
OutputStream* GetOutputStreamOrNull(BleSocket& socket) {
|
||||
if (socket.GetRemotePeripheral().IsValid()) return &socket.GetOutputStream();
|
||||
if (socket.IsValid()) {
|
||||
return &socket.GetOutputStream();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
InputStream* GetInputStreamOrNull(BleSocket& socket) {
|
||||
if (socket.GetRemotePeripheral().IsValid()) return &socket.GetInputStream();
|
||||
if (socket.IsValid()) {
|
||||
return &socket.GetInputStream();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -56,9 +64,8 @@ int BleEndpointChannel::GetMaxTransmitPacketSize() const {
|
||||
void BleEndpointChannel::CloseImpl() {
|
||||
auto status = ble_socket_.Close();
|
||||
if (!status.Ok()) {
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Failed to close underlying socket for BleEndpointChannel "
|
||||
<< GetName() << ": exception=" << status.value;
|
||||
LOG(INFO) << "Failed to close underlying socket for BleEndpointChannel "
|
||||
<< GetName() << ": exception=" << status.value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,15 +32,14 @@ namespace {
|
||||
constexpr int kDefaultBleL2capMaxTransmitPacketSize = 1024; // 1024 bytes
|
||||
|
||||
OutputStream* GetOutputStreamOrNull(BleL2capSocket& socket) {
|
||||
if (socket.GetRemotePeripheral().IsValid()) {
|
||||
if (socket.IsValid()) {
|
||||
return &socket.GetOutputStream();
|
||||
}
|
||||
LOG(WARNING) << "GetOutputStreamOrNull: socket is not valid";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
InputStream* GetInputStreamOrNull(BleL2capSocket& socket) {
|
||||
if (socket.GetRemotePeripheral().IsValid()) {
|
||||
if (socket.IsValid()) {
|
||||
return &socket.GetInputStream();
|
||||
}
|
||||
return nullptr;
|
||||
|
||||
@@ -17,8 +17,12 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "connections/implementation/base_endpoint_channel.h"
|
||||
#include "internal/platform/ble_v2.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
@@ -26,14 +30,14 @@ namespace connections {
|
||||
namespace {
|
||||
|
||||
OutputStream* GetOutputStreamOrNull(BleV2Socket& socket) {
|
||||
if (socket.GetRemotePeripheral().IsValid()) {
|
||||
if (socket.IsValid()) {
|
||||
return &socket.GetOutputStream();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
InputStream* GetInputStreamOrNull(BleV2Socket& socket) {
|
||||
if (socket.GetRemotePeripheral().IsValid()) {
|
||||
if (socket.IsValid()) {
|
||||
return &socket.GetInputStream();
|
||||
}
|
||||
return nullptr;
|
||||
@@ -61,9 +65,8 @@ int BleV2EndpointChannel::GetMaxTransmitPacketSize() const {
|
||||
void BleV2EndpointChannel::CloseImpl() {
|
||||
Exception status = ble_socket_.Close();
|
||||
if (!status.Ok()) {
|
||||
NEARBY_LOGS(WARNING)
|
||||
<< "Failed to close underlying socket for BleEndpointChannel "
|
||||
<< GetName() << ": exception=" << status.value;
|
||||
LOG(WARNING) << "Failed to close underlying socket for BleEndpointChannel "
|
||||
<< GetName() << ": exception=" << status.value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,13 @@
|
||||
#include "connections/implementation/bluetooth_endpoint_channel.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "connections/implementation/base_endpoint_channel.h"
|
||||
#include "internal/platform/bluetooth_classic.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
@@ -25,12 +29,16 @@ namespace connections {
|
||||
namespace {
|
||||
|
||||
OutputStream* GetOutputStreamOrNull(BluetoothSocket& socket) {
|
||||
if (socket.GetRemoteDevice().IsValid()) return &socket.GetOutputStream();
|
||||
if (socket.IsValid()) {
|
||||
return &socket.GetOutputStream();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
InputStream* GetInputStreamOrNull(BluetoothSocket& socket) {
|
||||
if (socket.GetRemoteDevice().IsValid()) return &socket.GetInputStream();
|
||||
if (socket.IsValid()) {
|
||||
return &socket.GetInputStream();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -56,15 +64,15 @@ int BluetoothEndpointChannel::GetMaxTransmitPacketSize() const {
|
||||
void BluetoothEndpointChannel::CloseImpl() {
|
||||
auto status = bluetooth_socket_.Close();
|
||||
if (!status.Ok()) {
|
||||
NEARBY_LOGS(INFO)
|
||||
LOG(WARNING)
|
||||
<< "Failed to close underlying socket for BluetoothEndpointChannel "
|
||||
<< GetName() << ": exception=" << status.value;
|
||||
}
|
||||
}
|
||||
|
||||
bool BluetoothEndpointChannel::EnableMultiplexSocket() {
|
||||
NEARBY_LOGS(INFO) << "BluetoothEndpointChannel MultiplexSocket will be "
|
||||
"enabled if the Bluetooth MultiplexSocket is valid";
|
||||
LOG(INFO) << "BluetoothEndpointChannel MultiplexSocket will be "
|
||||
"enabled if the Bluetooth MultiplexSocket is valid";
|
||||
bluetooth_socket_.EnableMultiplexSocket();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user