mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Retry the Hotspot IP address query procedure
PiperOrigin-RevId: 477592843
This commit is contained in:
@@ -87,7 +87,9 @@ using ::winrt::Windows::Networking::Sockets::StreamSocketListener;
|
||||
using ::winrt::Windows::Networking::Sockets::
|
||||
StreamSocketListenerConnectionReceivedEventArgs;
|
||||
|
||||
// using winrt::Windows::Foundation::IInspectable;
|
||||
constexpr int kMaxRetries = 3;
|
||||
constexpr int kRetryIntervalMilliSeconds = 300;
|
||||
constexpr int kMaxScans = 2;
|
||||
|
||||
// WifiHotspotSocket wraps the socket functions to read and write stream.
|
||||
// In WiFi HOTSPOT, A WifiHotspotSocket will be passed to
|
||||
|
||||
@@ -24,12 +24,6 @@ namespace location {
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
|
||||
namespace {
|
||||
constexpr int kMaxRetries = 3;
|
||||
constexpr int kRetryIntervalMilliSeconds = 300;
|
||||
constexpr int kMaxScans = 2;
|
||||
} // namespace
|
||||
|
||||
WifiHotspotMedium::WifiHotspotMedium() {}
|
||||
|
||||
WifiHotspotMedium::~WifiHotspotMedium() {
|
||||
|
||||
@@ -29,11 +29,7 @@ namespace location {
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
namespace {
|
||||
|
||||
using ::winrt::Windows::Networking::Sockets::SocketQualityOfService;
|
||||
|
||||
constexpr int kMaxRetries = 3;
|
||||
|
||||
} // namespace
|
||||
|
||||
WifiHotspotServerSocket::WifiHotspotServerSocket(int port) : port_(port) {}
|
||||
@@ -122,10 +118,19 @@ Exception WifiHotspotServerSocket::Close() {
|
||||
|
||||
bool WifiHotspotServerSocket::listen() {
|
||||
// Get current IP addresses of the device.
|
||||
hotspot_ipaddr_ = GetHotspotIpAddresses();
|
||||
|
||||
for (int i = 0; i < kMaxRetries; i++) {
|
||||
hotspot_ipaddr_ = GetHotspotIpAddresses();
|
||||
if (hotspot_ipaddr_.empty()) {
|
||||
NEARBY_LOGS(WARNING) << "Failed to find Hotspot's IP addr for the try: "
|
||||
<< i + 1 << ". Wait " << kRetryIntervalMilliSeconds
|
||||
<< "ms snd try again";
|
||||
Sleep(kRetryIntervalMilliSeconds);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hotspot_ipaddr_.empty()) {
|
||||
NEARBY_LOGS(WARNING) << "failed to start accepting connection without IP "
|
||||
NEARBY_LOGS(WARNING) << "Failed to start accepting connection without IP "
|
||||
"addresses configured on computer.";
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user