diff --git a/internal/platform/flags/nearby_platform_feature_flags.h b/internal/platform/flags/nearby_platform_feature_flags.h index 9259140b..f76a33c1 100644 --- a/internal/platform/flags/nearby_platform_feature_flags.h +++ b/internal/platform/flags/nearby_platform_feature_flags.h @@ -61,6 +61,10 @@ constexpr auto kEnableHotspotDhcpRenew = constexpr auto kEnableIntelPieSdk = flags::Flag(kConfigPackage, "45428547", false); +// Enable/Disable IPv6 dual stack support on Windows. +constexpr auto kEnableIpv6DualStack = + flags::Flag(kConfigPackage, "45733519", false); + // Enable/Disable new Bluetooth refactor constexpr auto kEnableNewBluetoothRefactor = flags::Flag(kConfigPackage, "45615156", false); diff --git a/internal/platform/implementation/windows/nearby_client_socket.h b/internal/platform/implementation/windows/nearby_client_socket.h index bb8b69b8..a455ece0 100644 --- a/internal/platform/implementation/windows/nearby_client_socket.h +++ b/internal/platform/implementation/windows/nearby_client_socket.h @@ -33,7 +33,7 @@ class NearbyClientSocket { ~NearbyClientSocket(); bool Connect(const std::string& ip_address, int port, - bool dual_stack = false); + bool dual_stack); ExceptionOr Read(std::int64_t size); ExceptionOr Skip(size_t offset); Exception Write(const ByteArray& data); diff --git a/internal/platform/implementation/windows/nearby_server_socket.h b/internal/platform/implementation/windows/nearby_server_socket.h index 1d90703e..a8055147 100644 --- a/internal/platform/implementation/windows/nearby_server_socket.h +++ b/internal/platform/implementation/windows/nearby_server_socket.h @@ -29,7 +29,7 @@ class NearbyServerSocket { NearbyServerSocket(); ~NearbyServerSocket(); - bool Listen(const std::string& ip_address, int port, bool dual_stack = false); + bool Listen(const std::string& ip_address, int port, bool dual_stack); std::unique_ptr Accept(); bool Close(); diff --git a/internal/platform/implementation/windows/wifi_hotspot.h b/internal/platform/implementation/windows/wifi_hotspot.h index 2d5913f9..11ff970d 100644 --- a/internal/platform/implementation/windows/wifi_hotspot.h +++ b/internal/platform/implementation/windows/wifi_hotspot.h @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -35,6 +34,7 @@ #include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" +#include "absl/types/optional.h" #include "internal/platform/byte_array.h" #include "internal/platform/cancellation_flag.h" #include "internal/platform/exception.h" @@ -45,7 +45,6 @@ #include "internal/platform/implementation/windows/wifi_hotspot_native.h" // WinRT headers -#include "absl/types/optional.h" #include "internal/platform/implementation/windows/generated/winrt/Windows.Devices.WiFiDirect.h" #include "internal/platform/implementation/windows/generated/winrt/Windows.Foundation.h" #include "internal/platform/implementation/windows/generated/winrt/base.h" @@ -53,8 +52,7 @@ #include "internal/platform/output_stream.h" #include "internal/platform/wifi_credential.h" -namespace nearby { -namespace windows { +namespace nearby::windows { using ::winrt::fire_and_forget; using ::winrt::Windows::Devices::WiFiDirect::WiFiDirectAdvertisementPublisher; @@ -96,8 +94,8 @@ class WifiHotspotSocket : public api::WifiHotspotSocket { // Returns Exception::kIo on error, Exception::kSuccess otherwise. Exception Close() override { return client_socket_->Close(); } - bool Connect(const std::string& ip_address, int port) { - return client_socket_->Connect(ip_address, port); + bool Connect(const std::string& ip_address, int port, bool dual_stack) { + return client_socket_->Connect(ip_address, port, dual_stack); } private: @@ -173,7 +171,7 @@ class WifiHotspotServerSocket : public api::WifiHotspotServerSocket { Exception Close() override; // Binds to local port - bool listen(); + bool Listen(bool dual_stack); NearbyServerSocket server_socket_; @@ -278,7 +276,6 @@ class WifiHotspotMedium : public api::WifiHotspotMedium { WifiHotspotNative wifi_hotspot_native_; }; -} // namespace windows -} // namespace nearby +} // namespace nearby::windows #endif // PLATFORM_IMPL_WINDOWS_WIFI_HOTSPOT_H_ diff --git a/internal/platform/implementation/windows/wifi_hotspot_medium.cc b/internal/platform/implementation/windows/wifi_hotspot_medium.cc index 682d3453..0caf4cc0 100644 --- a/internal/platform/implementation/windows/wifi_hotspot_medium.cc +++ b/internal/platform/implementation/windows/wifi_hotspot_medium.cc @@ -139,7 +139,10 @@ std::unique_ptr WifiHotspotMedium::ConnectToService( }); } - bool result = wifi_hotspot_socket->Connect(ipv4_address, port); + bool dual_stack = NearbyFlags::GetInstance().GetBoolFlag( + platform::config_package_nearby::nearby_platform_feature:: + kEnableIpv6DualStack); + bool result = wifi_hotspot_socket->Connect(ipv4_address, port, dual_stack); if (!result) { LOG(WARNING) << "reconnect to service at " << (i + 1) << "th times"; Sleep(wifi_hotspot_retry_interval_millis); @@ -170,7 +173,10 @@ WifiHotspotMedium::ListenForService(int port) { auto server_socket = std::make_unique(port); server_socket_ptr_ = server_socket.get(); - if (server_socket->listen()) { + bool dual_stack = NearbyFlags::GetInstance().GetBoolFlag( + platform::config_package_nearby::nearby_platform_feature:: + kEnableIpv6DualStack); + if (server_socket->Listen(dual_stack)) { medium_status_ |= kMediumStatusAccepting; // Setup close notifier after listen started. diff --git a/internal/platform/implementation/windows/wifi_hotspot_server_socket.cc b/internal/platform/implementation/windows/wifi_hotspot_server_socket.cc index 8063341a..972fc6a2 100644 --- a/internal/platform/implementation/windows/wifi_hotspot_server_socket.cc +++ b/internal/platform/implementation/windows/wifi_hotspot_server_socket.cc @@ -38,8 +38,7 @@ #include "internal/platform/implementation/windows/wifi_hotspot.h" #include "internal/platform/logging.h" -namespace nearby { -namespace windows { +namespace nearby::windows { namespace { using ::winrt::Windows::Networking::Connectivity::NetworkInformation; using ::winrt::Windows::Networking::HostNameType; @@ -90,7 +89,7 @@ Exception WifiHotspotServerSocket::Close() { return {Exception::kSuccess}; } -bool WifiHotspotServerSocket::listen() { +bool WifiHotspotServerSocket::Listen(bool dual_stack) { // Get current IP addresses of the device. int64_t ip_address_max_retries = NearbyFlags::GetInstance().GetInt64Flag( platform::config_package_nearby::nearby_platform_feature:: @@ -118,7 +117,7 @@ bool WifiHotspotServerSocket::listen() { return false; } - if (!server_socket_.Listen(hotspot_ipaddr_, port_)) { + if (!server_socket_.Listen(hotspot_ipaddr_, port_, dual_stack)) { LOG(ERROR) << "Failed to listen socket."; return false; } @@ -175,5 +174,4 @@ std::string WifiHotspotServerSocket::GetHotspotIpAddress() const { } } -} // namespace windows -} // namespace nearby +} // namespace nearby::windows diff --git a/internal/platform/implementation/windows/wifi_hotspot_test.cc b/internal/platform/implementation/windows/wifi_hotspot_test.cc index 3f4bf4a3..73a20cee 100644 --- a/internal/platform/implementation/windows/wifi_hotspot_test.cc +++ b/internal/platform/implementation/windows/wifi_hotspot_test.cc @@ -25,8 +25,7 @@ #include "internal/platform/logging.h" #include "internal/platform/wifi_credential.h" -namespace nearby { -namespace windows { +namespace nearby::windows { namespace { TEST(WifiHotspotMedium, DISABLED_StartWifiHotspot) { @@ -74,7 +73,7 @@ TEST(WifiHotspotMedium, DISABLED_WifiHotspotServerStartListen) { EXPECT_TRUE(hotspot_medium.StartWifiHotspot(&hotspot_credentials)); absl::SleepFor(absl::Seconds(1)); std::unique_ptr server_socket = - hotspot_medium.ListenForService(0); + hotspot_medium.ListenForService(/*port=*/0); absl::SleepFor(absl::Seconds(10)); std::unique_ptr client_socket = server_socket->Accept(); @@ -140,5 +139,4 @@ TEST(WifiHotspotMedium, DISABLED_ConnectWifiHotspot) { } } // namespace -} // namespace windows -} // namespace nearby +} // namespace nearby::windows diff --git a/internal/platform/implementation/windows/wifi_lan.h b/internal/platform/implementation/windows/wifi_lan.h index 391f8375..7fa9a90e 100644 --- a/internal/platform/implementation/windows/wifi_lan.h +++ b/internal/platform/implementation/windows/wifi_lan.h @@ -40,7 +40,6 @@ #include "absl/types/optional.h" #include "internal/platform/byte_array.h" #include "internal/platform/cancellation_flag.h" -#include "internal/platform/count_down_latch.h" #include "internal/platform/exception.h" #include "internal/platform/implementation/cancelable.h" #include "internal/platform/implementation/wifi_lan.h" @@ -49,51 +48,19 @@ #include "internal/platform/implementation/windows/scheduled_executor.h" #include "internal/platform/implementation/windows/wifi_lan_mdns.h" #include "internal/platform/input_stream.h" -#include "internal/platform/mutex.h" #include "internal/platform/nsd_service_info.h" #include "internal/platform/output_stream.h" -#include "internal/platform/scheduled_executor.h" // WinRT headers #include "internal/platform/implementation/windows/generated/winrt/Windows.Devices.Enumeration.h" #include "internal/platform/implementation/windows/generated/winrt/Windows.Foundation.Collections.h" #include "internal/platform/implementation/windows/generated/winrt/Windows.Foundation.h" -#include "internal/platform/implementation/windows/generated/winrt/Windows.Networking.Connectivity.h" #include "internal/platform/implementation/windows/generated/winrt/Windows.Networking.ServiceDiscovery.Dnssd.h" #include "internal/platform/implementation/windows/generated/winrt/Windows.Networking.Sockets.h" #include "internal/platform/implementation/windows/generated/winrt/Windows.Storage.Streams.h" #include "internal/platform/implementation/windows/generated/winrt/base.h" -namespace nearby { -namespace windows { - -using winrt::fire_and_forget; -using winrt::Windows::Devices::Enumeration::DeviceInformation; -using winrt::Windows::Devices::Enumeration::DeviceInformationKind; -using winrt::Windows::Devices::Enumeration::DeviceInformationUpdate; -using winrt::Windows::Devices::Enumeration::DeviceWatcher; -using winrt::Windows::Devices::Enumeration::DeviceWatcherStatus; -using winrt::Windows::Foundation::IInspectable; -using winrt::Windows::Foundation::Collections::IMapView; -using winrt::Windows::Networking::HostName; -using winrt::Windows::Networking::HostNameType; -using winrt::Windows::Networking::Connectivity::NetworkInformation; -using winrt::Windows::Networking::ServiceDiscovery::Dnssd:: - DnssdRegistrationResult; -using winrt::Windows::Networking::ServiceDiscovery::Dnssd:: - DnssdRegistrationStatus; -using winrt::Windows::Networking::ServiceDiscovery::Dnssd::DnssdServiceInstance; -using winrt::Windows::Networking::Sockets::StreamSocket; -using winrt::Windows::Networking::Sockets::StreamSocketListener; -using winrt::Windows::Networking::Sockets:: - StreamSocketListenerConnectionReceivedEventArgs; -using winrt::Windows::Networking::Sockets::StreamSocketListenerInformation; -using winrt::Windows::Storage::Streams::Buffer; -using winrt::Windows::Storage::Streams::DataReader; -using winrt::Windows::Storage::Streams::IBuffer; -using winrt::Windows::Storage::Streams::IInputStream; -using winrt::Windows::Storage::Streams::InputStreamOptions; -using winrt::Windows::Storage::Streams::IOutputStream; +namespace nearby::windows { // WifiLanSocket wraps the socket functions to read and write stream. // In WiFi LAN, A WifiLanSocket will be passed to StartAcceptingConnections's @@ -102,7 +69,8 @@ using winrt::Windows::Storage::Streams::IOutputStream; class WifiLanSocket : public api::WifiLanSocket { public: WifiLanSocket(); - explicit WifiLanSocket(StreamSocket socket); + explicit WifiLanSocket( + winrt::Windows::Networking::Sockets::StreamSocket socket); explicit WifiLanSocket(std::unique_ptr socket); WifiLanSocket(WifiLanSocket&) = default; WifiLanSocket(WifiLanSocket&&) = default; @@ -127,13 +95,14 @@ class WifiLanSocket : public api::WifiLanSocket { // Returns Exception::kIo on error, Exception::kSuccess otherwise. Exception Close() override; - bool Connect(const std::string& ip_address, int port); + bool Connect(const std::string& ip_address, int port, bool dual_stack); private: // A simple wrapper to handle input stream of socket class SocketInputStream : public InputStream { public: - explicit SocketInputStream(IInputStream input_stream); + explicit SocketInputStream( + winrt::Windows::Storage::Streams::IInputStream input_stream); explicit SocketInputStream(NearbyClientSocket* client_socket); ~SocketInputStream() = default; @@ -142,15 +111,16 @@ class WifiLanSocket : public api::WifiLanSocket { Exception Close() override; private: - IInputStream input_stream_{nullptr}; - Buffer read_buffer_{nullptr}; + winrt::Windows::Storage::Streams::IInputStream input_stream_{nullptr}; + winrt::Windows::Storage::Streams::Buffer read_buffer_{nullptr}; NearbyClientSocket* client_socket_{nullptr}; }; // A simple wrapper to handle output stream of socket class SocketOutputStream : public OutputStream { public: - explicit SocketOutputStream(IOutputStream output_stream); + explicit SocketOutputStream( + winrt::Windows::Storage::Streams::IOutputStream output_stream); explicit SocketOutputStream(NearbyClientSocket* client_socket); ~SocketOutputStream() = default; @@ -159,12 +129,12 @@ class WifiLanSocket : public api::WifiLanSocket { Exception Close() override; private: - IOutputStream output_stream_{nullptr}; + winrt::Windows::Storage::Streams::IOutputStream output_stream_{nullptr}; NearbyClientSocket* client_socket_{nullptr}; }; // Internal properties - StreamSocket stream_soket_{nullptr}; + winrt::Windows::Networking::Sockets::StreamSocket stream_soket_{nullptr}; SocketInputStream input_stream_{nullptr}; SocketOutputStream output_stream_{nullptr}; @@ -175,7 +145,7 @@ class WifiLanSocket : public api::WifiLanSocket { // accepts connection from clients. class WifiLanServerSocket : public api::WifiLanServerSocket { public: - explicit WifiLanServerSocket(int port = 0); + explicit WifiLanServerSocket(int port); WifiLanServerSocket(WifiLanServerSocket&) = default; WifiLanServerSocket(WifiLanServerSocket&&) = default; ~WifiLanServerSocket() override; @@ -191,7 +161,8 @@ class WifiLanServerSocket : public api::WifiLanServerSocket { // Sets port void SetPort(int port) { port_ = port; } - StreamSocketListener GetSocketListener() const { + winrt::Windows::Networking::Sockets::StreamSocketListener GetSocketListener() + const { return stream_socket_listener_; } @@ -212,18 +183,21 @@ class WifiLanServerSocket : public api::WifiLanServerSocket { Exception Close() override; // Binds to local port - bool listen(); + bool Listen(bool dual_stack); private: // The listener is accepting incoming connections - fire_and_forget Listener_ConnectionReceived( - StreamSocketListener listener, - StreamSocketListenerConnectionReceivedEventArgs const& args); + winrt::fire_and_forget Listener_ConnectionReceived( + winrt::Windows::Networking::Sockets::StreamSocketListener listener, + winrt::Windows::Networking::Sockets:: + StreamSocketListenerConnectionReceivedEventArgs const& args); mutable absl::Mutex mutex_; absl::CondVar cond_; - std::deque pending_sockets_ ABSL_GUARDED_BY(mutex_); - StreamSocketListener stream_socket_listener_{nullptr}; + std::deque pending_sockets_ + ABSL_GUARDED_BY(mutex_); + winrt::Windows::Networking::Sockets::StreamSocketListener + stream_socket_listener_{nullptr}; winrt::event_token listener_event_token_{}; // Close notifier @@ -268,7 +242,7 @@ class WifiLanMedium : public api::WifiLanMedium { CancellationFlag* cancellation_flag) override; std::unique_ptr ListenForService( - int port = 0) override; + int port) override; absl::optional> GetDynamicPortRange() override { @@ -318,15 +292,23 @@ class WifiLanMedium : public api::WifiLanMedium { // The API gets IP addresses, service name and text attributes of mDNS // from these properties, ExceptionOr GetNsdServiceInformation( - IMapView properties, bool is_device_found); + winrt::Windows::Foundation::Collections::IMapView< + winrt::hstring, winrt::Windows::Foundation::IInspectable> + properties, + bool is_device_found); // mDNS callbacks for advertising and discovery - fire_and_forget Watcher_DeviceAdded(DeviceWatcher sender, - DeviceInformation deviceInfo); - fire_and_forget Watcher_DeviceUpdated( - DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate); - fire_and_forget Watcher_DeviceRemoved( - DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate); + winrt::fire_and_forget Watcher_DeviceAdded( + winrt::Windows::Devices::Enumeration::DeviceWatcher sender, + winrt::Windows::Devices::Enumeration::DeviceInformation deviceInfo); + winrt::fire_and_forget Watcher_DeviceUpdated( + winrt::Windows::Devices::Enumeration::DeviceWatcher sender, + winrt::Windows::Devices::Enumeration::DeviceInformationUpdate + deviceInfoUpdate); + winrt::fire_and_forget Watcher_DeviceRemoved( + winrt::Windows::Devices::Enumeration::DeviceWatcher sender, + winrt::Windows::Devices::Enumeration::DeviceInformationUpdate + deviceInfoUpdate); // Gets error message from exception pointer std::string GetErrorMessage(std::exception_ptr eptr); @@ -338,11 +320,13 @@ class WifiLanMedium : public api::WifiLanMedium { // // Advertising properties - DnssdServiceInstance dnssd_service_instance_{nullptr}; - DnssdRegistrationResult dnssd_regirstraion_result_{nullptr}; + winrt::Windows::Networking::ServiceDiscovery::Dnssd::DnssdServiceInstance + dnssd_service_instance_{nullptr}; + winrt::Windows::Networking::ServiceDiscovery::Dnssd::DnssdRegistrationResult + dnssd_regirstraion_result_{nullptr}; // Discovery properties - DeviceWatcher device_watcher_{nullptr}; + winrt::Windows::Devices::Enumeration::DeviceWatcher device_watcher_{nullptr}; winrt::event_token device_watcher_added_event_token; winrt::event_token device_watcher_updated_event_token; winrt::event_token device_watcher_removed_event_token; @@ -378,7 +362,6 @@ class WifiLanMedium : public api::WifiLanMedium { std::shared_ptr connection_timeout_ = nullptr; }; -} // namespace windows -} // namespace nearby +} // namespace nearby::windows #endif // PLATFORM_IMPL_WINDOWS_WIFI_LAN_H_ diff --git a/internal/platform/implementation/windows/wifi_lan_medium.cc b/internal/platform/implementation/windows/wifi_lan_medium.cc index 7d30b760..3643dbf5 100644 --- a/internal/platform/implementation/windows/wifi_lan_medium.cc +++ b/internal/platform/implementation/windows/wifi_lan_medium.cc @@ -45,15 +45,25 @@ #include "internal/platform/exception.h" #include "internal/platform/feature_flags.h" #include "internal/platform/flags/nearby_platform_feature_flags.h" +#include "internal/platform/implementation/windows/generated/winrt/Windows.Devices.Enumeration.h" +#include "internal/platform/implementation/windows/generated/winrt/Windows.Foundation.Collections.h" +#include "internal/platform/implementation/windows/generated/winrt/Windows.Networking.Connectivity.h" #include "internal/platform/implementation/windows/string_utils.h" #include "internal/platform/implementation/windows/utils.h" #include "internal/platform/logging.h" #include "internal/platform/nsd_service_info.h" #include "internal/platform/runnable.h" -namespace nearby { -namespace windows { +namespace nearby::windows { namespace { +using ::winrt::fire_and_forget; +using ::winrt::Windows::Devices::Enumeration::DeviceInformation; +using ::winrt::Windows::Devices::Enumeration::DeviceInformationKind; +using ::winrt::Windows::Devices::Enumeration::DeviceInformationUpdate; +using ::winrt::Windows::Devices::Enumeration::DeviceWatcher; +using ::winrt::Windows::Foundation::Collections::IMapView; +using ::winrt::Windows::Networking::Connectivity::NetworkInformation; + // mDNS text attributes constexpr absl::string_view kDeviceEndpointInfo = "n"; constexpr absl::string_view kDeviceIpv4 = "IPv4"; @@ -256,7 +266,10 @@ std::unique_ptr WifiLanMedium::ConnectToService( }); } - bool result = wifi_lan_socket->Connect(ipv4_address, port); + bool dual_stack = NearbyFlags::GetInstance().GetBoolFlag( + platform::config_package_nearby::nearby_platform_feature:: + kEnableIpv6DualStack); + bool result = wifi_lan_socket->Connect(ipv4_address, port, dual_stack); if (!result) { LOG(ERROR) << "failed to connect to service " << ipv4_address << ":" << port; @@ -281,7 +294,10 @@ std::unique_ptr WifiLanMedium::ListenForService( std::make_unique(port); WifiLanServerSocket* server_socket_ptr = server_socket.get(); - if (server_socket->listen()) { + bool dual_stack = NearbyFlags::GetInstance().GetBoolFlag( + platform::config_package_nearby::nearby_platform_feature:: + kEnableIpv6DualStack); + if (server_socket->Listen(dual_stack)) { int port = server_socket_ptr->GetPort(); LOG(INFO) << "started to listen serive on IP:port " << ipaddr_4bytes_to_dotdecimal_string( @@ -652,5 +668,4 @@ std::string WifiLanMedium::GetErrorMessage(std::exception_ptr eptr) { } } -} // namespace windows -} // namespace nearby +} // namespace nearby::windows diff --git a/internal/platform/implementation/windows/wifi_lan_server_socket.cc b/internal/platform/implementation/windows/wifi_lan_server_socket.cc index c6e09059..30ccf183 100644 --- a/internal/platform/implementation/windows/wifi_lan_server_socket.cc +++ b/internal/platform/implementation/windows/wifi_lan_server_socket.cc @@ -22,9 +22,7 @@ #include "absl/functional/any_invocable.h" #include "absl/synchronization/mutex.h" -#include "internal/flags/nearby_flags.h" #include "internal/platform/exception.h" -#include "internal/platform/flags/nearby_platform_feature_flags.h" #include "internal/platform/implementation/wifi_lan.h" #include "internal/platform/implementation/windows/generated/winrt/Windows.Networking.Sockets.h" #include "internal/platform/implementation/windows/nearby_server_socket.h" @@ -32,13 +30,13 @@ #include "internal/platform/implementation/windows/wifi_lan.h" #include "internal/platform/logging.h" -namespace nearby { -namespace windows { +namespace nearby::windows { namespace { - -using ::winrt::Windows::Networking::Sockets::SocketQualityOfService; - -} +using ::winrt::fire_and_forget; +using ::winrt::Windows::Networking::Sockets::StreamSocketListener; +using ::winrt::Windows::Networking::Sockets:: + StreamSocketListenerConnectionReceivedEventArgs; +} // namespace WifiLanServerSocket::WifiLanServerSocket(int port) : port_(port) {} @@ -59,9 +57,7 @@ std::string WifiLanServerSocket::GetIPAddress() const { } // Returns socket port. -int WifiLanServerSocket::GetPort() const { - return server_socket_.GetPort(); -} +int WifiLanServerSocket::GetPort() const { return server_socket_.GetPort(); } // Blocks until either: // - at least one incoming connection request is available, or @@ -124,9 +120,9 @@ Exception WifiLanServerSocket::Close() { } } -bool WifiLanServerSocket::listen() { +bool WifiLanServerSocket::Listen(bool dual_stack) { // Listen on all interfaces. - if (!server_socket_.Listen("", port_)) { + if (!server_socket_.Listen("", port_, dual_stack)) { LOG(ERROR) << "Failed to listen socket at port:" << port_; return false; } @@ -148,5 +144,4 @@ fire_and_forget WifiLanServerSocket::Listener_ConnectionReceived( return fire_and_forget{}; } -} // namespace windows -} // namespace nearby +} // namespace nearby::windows diff --git a/internal/platform/implementation/windows/wifi_lan_socket.cc b/internal/platform/implementation/windows/wifi_lan_socket.cc index 9cfec6a9..9d4fd875 100644 --- a/internal/platform/implementation/windows/wifi_lan_socket.cc +++ b/internal/platform/implementation/windows/wifi_lan_socket.cc @@ -23,14 +23,20 @@ #include "internal/platform/byte_array.h" #include "internal/platform/exception.h" #include "internal/platform/flags/nearby_platform_feature_flags.h" +#include "internal/platform/implementation/windows/generated/winrt/Windows.Networking.Sockets.h" +#include "internal/platform/implementation/windows/generated/winrt/Windows.Storage.Streams.h" #include "internal/platform/implementation/windows/nearby_client_socket.h" #include "internal/platform/implementation/windows/wifi_lan.h" #include "internal/platform/input_stream.h" #include "internal/platform/logging.h" #include "internal/platform/output_stream.h" -namespace nearby { -namespace windows { +namespace nearby::windows { +namespace { +using ::winrt::Windows::Networking::Sockets::StreamSocket; +using ::winrt::Windows::Storage::Streams::IInputStream; +using ::winrt::Windows::Storage::Streams::IOutputStream; +} // namespace WifiLanSocket::WifiLanSocket() { client_socket_ = std::make_unique(); @@ -68,8 +74,9 @@ Exception WifiLanSocket::Close() { return {Exception::kSuccess}; } -bool WifiLanSocket::Connect(const std::string& ip_address, int port) { - return client_socket_->Connect(ip_address, port); +bool WifiLanSocket::Connect(const std::string& ip_address, + int port, bool dual_stack) { + return client_socket_->Connect(ip_address, port, dual_stack); } // SocketInputStream @@ -143,5 +150,4 @@ Exception WifiLanSocket::SocketOutputStream::Close() { return client_socket_->Close(); } -} // namespace windows -} // namespace nearby +} // namespace nearby::windows