From 5b90c5fbf7d21d745a7c7ccae0c17e5380912d1e Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 17 Mar 2015 13:45:27 +0100 Subject: [PATCH] Convert WinVNC to the new TcpListener API --- win/winvnc/ManagedListener.cxx | 51 ++++++++++++++++++++++++---------- win/winvnc/ManagedListener.h | 6 ++-- win/winvnc/VNCServerWin32.cxx | 4 +-- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/win/winvnc/ManagedListener.cxx b/win/winvnc/ManagedListener.cxx index e7728bc6..25d8dc0f 100644 --- a/win/winvnc/ManagedListener.cxx +++ b/win/winvnc/ManagedListener.cxx @@ -26,12 +26,16 @@ static LogWriter vlog("ManagedListener"); ManagedListener::ManagedListener(SocketManager* mgr) -: sock(0), filter(0), manager(mgr), addrChangeNotifier(0), server(0), port(0), localOnly(false) { +: filter(0), manager(mgr), addrChangeNotifier(0), server(0), port(0), localOnly(false) { } ManagedListener::~ManagedListener() { - if (sock) - manager->remListener(sock); + if (!sockets.empty()) { + std::list::iterator iter; + for (iter = sockets.begin(); iter != sockets.end(); ++iter) + manager->remListener(&*iter); + sockets.clear(); + } delete filter; } @@ -57,8 +61,11 @@ void ManagedListener::setFilter(const char* filterStr) { vlog.info("set filter to %s", filterStr); delete filter; filter = new network::TcpFilter(filterStr); - if (sock && !localOnly) - sock->setFilter(filter); + if (!sockets.empty() && !localOnly) { + std::list::iterator iter; + for (iter = sockets.begin(); iter != sockets.end(); ++iter) + iter->setFilter(filter); + } } void ManagedListener::setAddressChangeNotifier(SocketManager::AddressChangeNotifier* acn) { @@ -68,26 +75,40 @@ void ManagedListener::setAddressChangeNotifier(SocketManager::AddressChangeNotif refresh(); } +bool ManagedListener::isListening() { + return !sockets.empty(); +} void ManagedListener::refresh() { - if (sock) - manager->remListener(sock); - sock = 0; + std::list::iterator iter; + if (!sockets.empty()) { + for (iter = sockets.begin(); iter != sockets.end(); ++iter) + manager->remListener(&*iter); + sockets.clear(); + } if (!server) return; try { - if (port) - sock = new network::TcpListener(NULL, port, localOnly); + if (port) { + if (localOnly) + network::createLocalTcpListeners(&sockets, port); + else + network::createTcpListeners(&sockets, NULL, port); + } } catch (rdr::Exception& e) { vlog.error("%s", e.str()); } - if (sock) { - if (!localOnly) - sock->setFilter(filter); + if (!sockets.empty()) { + if (!localOnly) { + for (iter = sockets.begin(); iter != sockets.end(); ++iter) + iter->setFilter(filter); + } try { - manager->addListener(sock, server, addrChangeNotifier); + for (iter = sockets.begin(); iter != sockets.end(); ++iter) + manager->addListener(&*iter, server, addrChangeNotifier); } catch (...) { - sock = 0; + // FIXME: Should unwind what we've added + sockets.clear(); throw; } } diff --git a/win/winvnc/ManagedListener.h b/win/winvnc/ManagedListener.h index e83aa0b6..1c7099fe 100644 --- a/win/winvnc/ManagedListener.h +++ b/win/winvnc/ManagedListener.h @@ -40,10 +40,12 @@ namespace winvnc { void setPort(int port, bool localOnly=false); void setFilter(const char* filter); void setAddressChangeNotifier(rfb::win32::SocketManager::AddressChangeNotifier* acn); - - network::TcpListener* sock; + + bool isListening(); + protected: void refresh(); + std::list sockets; network::TcpFilter* filter; rfb::win32::SocketManager* manager; rfb::win32::SocketManager::AddressChangeNotifier* addrChangeNotifier; diff --git a/win/winvnc/VNCServerWin32.cxx b/win/winvnc/VNCServerWin32.cxx index dbbf7c79..27aea9f6 100644 --- a/win/winvnc/VNCServerWin32.cxx +++ b/win/winvnc/VNCServerWin32.cxx @@ -43,7 +43,7 @@ static IntParameter http_port("HTTPPortNumber", static IntParameter port_number("PortNumber", "TCP/IP port on which the server will accept connections", 5900); static StringParameter hosts("Hosts", - "Filter describing which hosts are allowed access to this server", "+0.0.0.0/0.0.0.0"); + "Filter describing which hosts are allowed access to this server", "+"); static BoolParameter localHost("LocalHost", "Only accept connections from via the local loop-back network interface", false); static BoolParameter queryOnlyIfLoggedOn("QueryOnlyIfLoggedOn", @@ -136,7 +136,7 @@ void VNCServerWin32::regConfigChanged() { httpSock.setPort(http_port, localHost); // -=- Update the Java viewer's web page port number. - httpServer.setRFBport(rfbSock.sock ? port_number : 0); + httpServer.setRFBport(rfbSock.isListening() ? port_number : 0); // -=- Update the TCP address filter for both ports, if open. CharArray pattern(hosts.getData()); -- 2.39.5