From 05ef8661b2f42cc5b889f3900b459d8a49a24db3 Mon Sep 17 00:00:00 2001 From: dknn Date: Sun, 15 Jul 2012 20:26:38 +0200 Subject: Handle all kind of ip in udp and screen sharing diff --git a/Swiften/Network/BoostUDPSocket.cpp b/Swiften/Network/BoostUDPSocket.cpp index cedaad4..4405091 100644 --- a/Swiften/Network/BoostUDPSocket.cpp +++ b/Swiften/Network/BoostUDPSocket.cpp @@ -52,24 +52,28 @@ BoostUDPSocket::~BoostUDPSocket() { } -void BoostUDPSocket::bind(int port) +void BoostUDPSocket::bind(const HostAddressPort& addr) { if (!socket_.is_open()) - socket_.open(boost::asio::ip::udp::v4()); - socket_.bind(boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port)); + socket_.open(addr.toEndpoint().protocol()); + socket_.bind(addr.toEndpoint()); +} + +void BoostUDPSocket::bindOnAvailablePort(const HostAddress &addr) +{ + bind(HostAddressPort(addr, 0)); } void BoostUDPSocket::listen() { - if (!socket_.is_open()) - socket_.open(boost::asio::ip::udp::v4()); - doRead(); + if (socket_.is_open()) + doRead(); } void BoostUDPSocket::connect(const HostAddressPort &address) { - if (!socket_.is_open()) - socket_.open(boost::asio::ip::udp::v4()); +// if (!socket_.is_open()) +// socket_.open(boost::asio::ip::udp::v4()); socket_.connect(address.toEndpoint()); // TODO: handle errors eventLoop->postEvent(boost::bind(boost::ref(onConnected)), shared_from_this()); } diff --git a/Swiften/Network/BoostUDPSocket.h b/Swiften/Network/BoostUDPSocket.h index c7de5b7..bb5014e 100644 --- a/Swiften/Network/BoostUDPSocket.h +++ b/Swiften/Network/BoostUDPSocket.h @@ -24,6 +24,7 @@ namespace boost { namespace Swift { class EventLoop; + class HostAddress; class HostAddressPort; class BoostUDPSocket : public UDPSocket, public EventOwner, public boost::enable_shared_from_this { @@ -36,7 +37,8 @@ namespace Swift { return ref(new BoostUDPSocket(ioService, eventLoop)); } - virtual void bind(int port); + virtual void bind(const HostAddressPort& addr); + virtual void bindOnAvailablePort(const HostAddress& addr); virtual void listen(); virtual void connect(const HostAddressPort& address); virtual void connectToFirstIncoming(); diff --git a/Swiften/Network/UDPSocket.h b/Swiften/Network/UDPSocket.h index 4ba9962..3a239f8 100644 --- a/Swiften/Network/UDPSocket.h +++ b/Swiften/Network/UDPSocket.h @@ -11,6 +11,7 @@ namespace Swift { class EventLoop; + class HostAddress; class HostAddressPort; class UDPSocket { @@ -19,7 +20,8 @@ namespace Swift { virtual ~UDPSocket() {} - virtual void bind(int port) = 0; + virtual void bind(const HostAddressPort& addr) = 0; + virtual void bindOnAvailablePort(const HostAddress& addr) = 0; virtual void listen() = 0; virtual void connect(const HostAddressPort& address) = 0; virtual void connectToFirstIncoming() = 0; diff --git a/Swiften/ScreenSharing/ScreenSharing.cpp b/Swiften/ScreenSharing/ScreenSharing.cpp index be3c8ab..c6c78e0 100644 --- a/Swiften/ScreenSharing/ScreenSharing.cpp +++ b/Swiften/ScreenSharing/ScreenSharing.cpp @@ -52,11 +52,11 @@ bool ScreenSharing::addBestCandidate(boost::shared_ptrcreateUDPSocket(); - serverSocket->bind(0); + serverSocket->bindOnAvailablePort(interface.getAddresses().front()); - candidate.hostAddressPort = HostAddressPort(interface.getAddresses().front(), serverSocket->getLocalAddress().getPort()); + candidate.hostAddressPort = serverSocket->getLocalAddress(); candidate.type = JingleRawUDPTransportPayload::Candidate::Host; transport->addCandidate(candidate); @@ -65,11 +65,11 @@ bool ScreenSharing::addBestCandidate(boost::shared_ptrcreateUDPSocket(); - serverSocket->bind(0); + serverSocket->bindOnAvailablePort(interfaces.front().getAddresses().front()); - candidate.hostAddressPort = HostAddressPort(interfaces.front().getAddresses().front(), serverSocket->getLocalAddress().getPort()); + candidate.hostAddressPort = serverSocket->getLocalAddress(); candidate.type = JingleRawUDPTransportPayload::Candidate::Host; transport->addCandidate(candidate); -- cgit v0.10.2-6-g49f6