Retry the Hotspot IP address query procedure

PiperOrigin-RevId: 477592843
This commit is contained in:
hai007
2022-09-28 17:26:17 -07:00
committed by Copybara-Service
parent f65e32ad32
commit ad93e1f47b
3 changed files with 15 additions and 14 deletions
@@ -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;
}