From e3a2be69c48893ef086110b8d92f1fadd004a997 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 3 May 2018 14:03:55 +0200 Subject: [PATCH] Use abstract SocketListener class Makes the code more general and not directly tied to specifically TCP sockets. --- common/network/Socket.h | 2 ++ common/network/TcpSocket.cxx | 8 ++++---- common/network/TcpSocket.h | 9 +++++---- unix/x0vncserver/x0vncserver.cxx | 8 ++++---- unix/xserver/hw/vnc/RFBGlue.cc | 2 +- unix/xserver/hw/vnc/XserverDesktop.cc | 14 +++++++------- unix/xserver/hw/vnc/XserverDesktop.h | 12 ++++++------ unix/xserver/hw/vnc/vncExtInit.cc | 4 ++-- vncviewer/vncviewer.cxx | 6 +++--- win/winvnc/ManagedListener.cxx | 8 ++++---- win/winvnc/ManagedListener.h | 2 +- 11 files changed, 39 insertions(+), 36 deletions(-) diff --git a/common/network/Socket.h b/common/network/Socket.h index 7a30cacf..382b2702 100644 --- a/common/network/Socket.h +++ b/common/network/Socket.h @@ -99,6 +99,8 @@ namespace network { // if one is installed. Otherwise, returns 0. virtual Socket* accept() = 0; + virtual int getMyPort() = 0; + // setFilter() applies the specified filter to all new connections void setFilter(ConnectionFilter* f) {filter = f;} int getFd() {return fd;} diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index 9603c385..4287132e 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -532,7 +532,7 @@ int TcpListener::getMyPort() { } -void network::createLocalTcpListeners(std::list *listeners, +void network::createLocalTcpListeners(std::list *listeners, int port) { struct addrinfo ai[2]; @@ -562,7 +562,7 @@ void network::createLocalTcpListeners(std::list *listeners, createTcpListeners(listeners, ai); } -void network::createTcpListeners(std::list *listeners, +void network::createTcpListeners(std::list *listeners, const char *addr, int port) { @@ -594,11 +594,11 @@ void network::createTcpListeners(std::list *listeners, } } -void network::createTcpListeners(std::list *listeners, +void network::createTcpListeners(std::list *listeners, const struct addrinfo *ai) { const struct addrinfo *current; - std::list new_listeners; + std::list new_listeners; initSockets(); diff --git a/common/network/TcpSocket.h b/common/network/TcpSocket.h index c1b142ff..74ff4c50 100644 --- a/common/network/TcpSocket.h +++ b/common/network/TcpSocket.h @@ -80,16 +80,17 @@ namespace network { virtual void shutdown(); virtual Socket* accept(); + virtual int getMyPort(); + static void getMyAddresses(std::list* result); - int getMyPort(); }; - void createLocalTcpListeners(std::list *listeners, + void createLocalTcpListeners(std::list *listeners, int port); - void createTcpListeners(std::list *listeners, + void createTcpListeners(std::list *listeners, const char *addr, int port); - void createTcpListeners(std::list *listeners, + void createTcpListeners(std::list *listeners, const struct addrinfo *ai); typedef struct vnc_sockaddr { diff --git a/unix/x0vncserver/x0vncserver.cxx b/unix/x0vncserver/x0vncserver.cxx index c8098f70..db917975 100644 --- a/unix/x0vncserver/x0vncserver.cxx +++ b/unix/x0vncserver/x0vncserver.cxx @@ -291,7 +291,7 @@ int main(int argc, char** argv) signal(SIGINT, CleanupSignalHandler); signal(SIGTERM, CleanupSignalHandler); - std::list listeners; + std::list listeners; try { TXWindow::init(dpy,"x0vncserver"); @@ -313,7 +313,7 @@ int main(int argc, char** argv) const char *hostsData = hostsFile.getData(); FileTcpFilter fileTcpFilter(hostsData); if (strlen(hostsData) != 0) - for (std::list::iterator i = listeners.begin(); + for (std::list::iterator i = listeners.begin(); i != listeners.end(); i++) (*i)->setFilter(&fileTcpFilter); @@ -335,7 +335,7 @@ int main(int argc, char** argv) FD_ZERO(&wfds); FD_SET(ConnectionNumber(dpy), &rfds); - for (std::list::iterator i = listeners.begin(); + for (std::list::iterator i = listeners.begin(); i != listeners.end(); i++) FD_SET((*i)->getFd(), &rfds); @@ -387,7 +387,7 @@ int main(int argc, char** argv) } // Accept new VNC connections - for (std::list::iterator i = listeners.begin(); + for (std::list::iterator i = listeners.begin(); i != listeners.end(); i++) { if (FD_ISSET((*i)->getFd(), &rfds)) { diff --git a/unix/xserver/hw/vnc/RFBGlue.cc b/unix/xserver/hw/vnc/RFBGlue.cc index c9153364..c09dfe6c 100644 --- a/unix/xserver/hw/vnc/RFBGlue.cc +++ b/unix/xserver/hw/vnc/RFBGlue.cc @@ -199,7 +199,7 @@ int vncIsTCPPortUsed(int port) { try { // Attempt to create TCPListeners on that port. - std::list dummy; + std::list dummy; network::createTcpListeners (&dummy, 0, port); while (!dummy.empty()) { delete dummy.back(); diff --git a/unix/xserver/hw/vnc/XserverDesktop.cc b/unix/xserver/hw/vnc/XserverDesktop.cc index 080943d0..4aac7655 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.cc +++ b/unix/xserver/hw/vnc/XserverDesktop.cc @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include #include @@ -107,8 +107,8 @@ public: XserverDesktop::XserverDesktop(int screenIndex_, - std::list listeners_, - std::list httpListeners_, + std::list listeners_, + std::list httpListeners_, const char* name, const rfb::PixelFormat &pf, int width, int height, void* fbptr, int stride) @@ -127,13 +127,13 @@ XserverDesktop::XserverDesktop(int screenIndex_, if (!httpListeners.empty ()) httpServer = new FileHTTPServer(this); - for (std::list::iterator i = listeners.begin(); + for (std::list::iterator i = listeners.begin(); i != listeners.end(); i++) { vncSetNotifyFd((*i)->getFd(), screenIndex, true, false); } - for (std::list::iterator i = httpListeners.begin(); + for (std::list::iterator i = httpListeners.begin(); i != httpListeners.end(); i++) { vncSetNotifyFd((*i)->getFd(), screenIndex, true, false); @@ -386,10 +386,10 @@ void XserverDesktop::handleSocketEvent(int fd, bool read, bool write) } bool XserverDesktop::handleListenerEvent(int fd, - std::list* sockets, + std::list* sockets, SocketServer* sockserv) { - std::list::iterator i; + std::list::iterator i; for (i = sockets->begin(); i != sockets->end(); i++) { if ((*i)->getFd() == fd) diff --git a/unix/xserver/hw/vnc/XserverDesktop.h b/unix/xserver/hw/vnc/XserverDesktop.h index f1c3e3e7..f866a4cc 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.h +++ b/unix/xserver/hw/vnc/XserverDesktop.h @@ -44,7 +44,7 @@ namespace rfb { class VNCServerST; } -namespace network { class TcpListener; class Socket; class SocketServer; } +namespace network { class SocketListener; class Socket; class SocketServer; } class XserverDesktop : public rfb::SDesktop, public rfb::FullFramePixelBuffer, public rdr::Substitutor, @@ -53,8 +53,8 @@ class XserverDesktop : public rfb::SDesktop, public rfb::FullFramePixelBuffer, public: XserverDesktop(int screenIndex, - std::list listeners_, - std::list httpListeners_, + std::list listeners_, + std::list httpListeners_, const char* name, const rfb::PixelFormat &pf, int width, int height, void* fbptr, int stride); virtual ~XserverDesktop(); @@ -109,7 +109,7 @@ public: protected: bool handleListenerEvent(int fd, - std::list* sockets, + std::list* sockets, network::SocketServer* sockserv); bool handleSocketEvent(int fd, network::SocketServer* sockserv, @@ -122,8 +122,8 @@ private: int screenIndex; rfb::VNCServerST* server; rfb::HTTPServer* httpServer; - std::list listeners; - std::list httpListeners; + std::list listeners; + std::list httpListeners; bool directFbptr; uint32_t queryConnectId; diff --git a/unix/xserver/hw/vnc/vncExtInit.cc b/unix/xserver/hw/vnc/vncExtInit.cc index 54cca953..f2674511 100644 --- a/unix/xserver/hw/vnc/vncExtInit.cc +++ b/unix/xserver/hw/vnc/vncExtInit.cc @@ -173,8 +173,8 @@ void vncExtensionInit(void) for (int scr = 0; scr < vncGetScreenCount(); scr++) { if (!desktop[scr]) { - std::list listeners; - std::list httpListeners; + std::list listeners; + std::list httpListeners; if (scr == 0 && vncInetdSock != -1) { if (network::TcpSocket::isListening(vncInetdSock)) { diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index 413260d9..f22648d4 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -547,7 +547,7 @@ int main(int argc, char** argv) #endif if (listenMode) { - std::list listeners; + std::list listeners; try { int port = 5500; if (isdigit(vncServerName[0])) @@ -561,7 +561,7 @@ int main(int argc, char** argv) while (sock == NULL) { fd_set rfds; FD_ZERO(&rfds); - for (std::list::iterator i = listeners.begin(); + for (std::list::iterator i = listeners.begin(); i != listeners.end(); i++) FD_SET((*i)->getFd(), &rfds); @@ -576,7 +576,7 @@ int main(int argc, char** argv) } } - for (std::list::iterator i = listeners.begin (); + for (std::list::iterator i = listeners.begin (); i != listeners.end(); i++) if (FD_ISSET((*i)->getFd(), &rfds)) { diff --git a/win/winvnc/ManagedListener.cxx b/win/winvnc/ManagedListener.cxx index 9137238a..a8c6f25e 100644 --- a/win/winvnc/ManagedListener.cxx +++ b/win/winvnc/ManagedListener.cxx @@ -31,7 +31,7 @@ ManagedListener::ManagedListener(SocketManager* mgr) ManagedListener::~ManagedListener() { if (!sockets.empty()) { - std::list::iterator iter; + std::list::iterator iter; for (iter = sockets.begin(); iter != sockets.end(); ++iter) manager->remListener(*iter); sockets.clear(); @@ -62,7 +62,7 @@ void ManagedListener::setFilter(const char* filterStr) { delete filter; filter = new network::TcpFilter(filterStr); if (!sockets.empty() && !localOnly) { - std::list::iterator iter; + std::list::iterator iter; for (iter = sockets.begin(); iter != sockets.end(); ++iter) (*iter)->setFilter(filter); } @@ -80,7 +80,7 @@ bool ManagedListener::isListening() { } void ManagedListener::refresh() { - std::list::iterator iter; + std::list::iterator iter; if (!sockets.empty()) { for (iter = sockets.begin(); iter != sockets.end(); ++iter) manager->remListener(*iter); @@ -107,7 +107,7 @@ void ManagedListener::refresh() { for (iter = sockets.begin(); iter != sockets.end(); ++iter) manager->addListener(*iter, server, addrChangeNotifier); } catch (...) { - std::list::iterator iter2; + std::list::iterator iter2; for (iter2 = sockets.begin(); iter2 != iter; ++iter2) manager->remListener(*iter2); for (; iter2 != sockets.end(); ++iter2) diff --git a/win/winvnc/ManagedListener.h b/win/winvnc/ManagedListener.h index e8d3c892..39223c79 100644 --- a/win/winvnc/ManagedListener.h +++ b/win/winvnc/ManagedListener.h @@ -45,7 +45,7 @@ namespace winvnc { protected: void refresh(); - std::list sockets; + std::list sockets; network::TcpFilter* filter; rfb::win32::SocketManager* manager; rfb::win32::SocketManager::AddressChangeNotifier* addrChangeNotifier; -- 2.39.5