diff --git a/internal/platform/implementation/windows/wifi_hotspot.h b/internal/platform/implementation/windows/wifi_hotspot.h index 852f2bb4..b2c75ea2 100644 --- a/internal/platform/implementation/windows/wifi_hotspot.h +++ b/internal/platform/implementation/windows/wifi_hotspot.h @@ -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 diff --git a/internal/platform/implementation/windows/wifi_hotspot_medium.cc b/internal/platform/implementation/windows/wifi_hotspot_medium.cc index dfd3104c..2becb306 100644 --- a/internal/platform/implementation/windows/wifi_hotspot_medium.cc +++ b/internal/platform/implementation/windows/wifi_hotspot_medium.cc @@ -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() { diff --git a/internal/platform/implementation/windows/wifi_hotspot_server_socket.cc b/internal/platform/implementation/windows/wifi_hotspot_server_socket.cc index 7ab318dc..d9f74e23 100644 --- a/internal/platform/implementation/windows/wifi_hotspot_server_socket.cc +++ b/internal/platform/implementation/windows/wifi_hotspot_server_socket.cc @@ -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; }