summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Network')
-rw-r--r--Swiften/Network/BoostUDPSocket.cpp20
-rw-r--r--Swiften/Network/BoostUDPSocket.h4
-rw-r--r--Swiften/Network/UDPSocket.h4
3 files changed, 18 insertions, 10 deletions
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<BoostUDPSocket> {
@@ -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;