From d77e2b01f972ef12b722e3ef9d22efdc241689c3 Mon Sep 17 00:00:00 2001 From: Carlos Santos Date: Tue, 9 Jan 2024 10:32:20 -0300 Subject: [PATCH] Remove the network::SocketServer interface. Move these RFB specific things to rfb::VNCServer, for clarity. Signed-off-by: Pierre Ossman Signed-off-by: Carlos Santos --- common/network/Socket.h | 35 ------------------------- common/rfb/VNCServer.h | 37 ++++++++++++++++++++++++--- common/rfb/VNCServerST.cxx | 6 ++--- common/rfb/VNCServerST.h | 5 +--- unix/x0vncserver/XDesktop.cxx | 2 ++ unix/xserver/hw/vnc/XserverDesktop.cc | 4 +-- unix/xserver/hw/vnc/XserverDesktop.h | 6 ++--- win/rfb_win32/SocketManager.cxx | 12 ++++++--- win/rfb_win32/SocketManager.h | 32 +++++++++++++---------- win/winvnc/ManagedListener.cxx | 2 +- win/winvnc/ManagedListener.h | 6 ++--- 11 files changed, 75 insertions(+), 72 deletions(-) diff --git a/common/network/Socket.h b/common/network/Socket.h index 117851c1..7085d73a 100644 --- a/common/network/Socket.h +++ b/common/network/Socket.h @@ -111,41 +111,6 @@ namespace network { SocketException(const char* text, int err_) : rdr::SystemException(text, err_) {} }; - class SocketServer { - public: - virtual ~SocketServer() {} - - // addSocket() tells the server to serve the Socket. The caller - // retains ownership of the Socket - the only way for the server - // to discard a Socket is by calling shutdown() on it. - // outgoing is set to true if the socket was created by connecting out - // to another host, or false if the socket was created by accept()ing - // an incoming connection. - virtual void addSocket(network::Socket* sock, bool outgoing=false) = 0; - - // removeSocket() tells the server to stop serving the Socket. The - // caller retains ownership of the Socket - the server must NOT - // delete the Socket! This call is used mainly to cause per-Socket - // resources to be freed. - virtual void removeSocket(network::Socket* sock) = 0; - - // getSockets() gets a list of sockets. This can be used to generate an - // fd_set for calling select(). - virtual void getSockets(std::list* sockets) = 0; - - // processSocketReadEvent() tells the server there is a Socket read event. - // The implementation can indicate that the Socket is no longer active - // by calling shutdown() on it. The caller will then call removeSocket() - // soon after processSocketEvent returns, to allow any pre-Socket - // resources to be tidied up. - virtual void processSocketReadEvent(network::Socket* sock) = 0; - - // processSocketReadEvent() tells the server there is a Socket write event. - // This is only necessary if the Socket has been put in non-blocking - // mode and needs this callback to flush the buffer. - virtual void processSocketWriteEvent(network::Socket* sock) = 0; - }; - } #endif // __NETWORK_SOCKET_H__ diff --git a/common/rfb/VNCServer.h b/common/rfb/VNCServer.h index 3f97634b..6d75f8f8 100644 --- a/common/rfb/VNCServer.h +++ b/common/rfb/VNCServer.h @@ -23,17 +23,46 @@ #ifndef __RFB_VNCSERVER_H__ #define __RFB_VNCSERVER_H__ -#include - #include #include #include +namespace network { class Socket; } + namespace rfb { - class VNCServer : public UpdateTracker, - public network::SocketServer { + class VNCServer : public UpdateTracker { public: + // addSocket() tells the server to serve the Socket. The caller + // retains ownership of the Socket - the only way for the server + // to discard a Socket is by calling shutdown() on it. + // outgoing is set to true if the socket was created by connecting out + // to another host, or false if the socket was created by accept()ing + // an incoming connection. + virtual void addSocket(network::Socket* sock, bool outgoing=false) = 0; + + // removeSocket() tells the server to stop serving the Socket. The + // caller retains ownership of the Socket - the server must NOT + // delete the Socket! This call is used mainly to cause per-Socket + // resources to be freed. + virtual void removeSocket(network::Socket* sock) = 0; + + // getSockets() gets a list of sockets. This can be used to generate an + // fd_set for calling select(). + virtual void getSockets(std::list* sockets) = 0; + + // processSocketReadEvent() tells the server there is a Socket read event. + // The implementation can indicate that the Socket is no longer active + // by calling shutdown() on it. The caller will then call removeSocket() + // soon after processSocketEvent returns, to allow any pre-Socket + // resources to be tidied up. + virtual void processSocketReadEvent(network::Socket* sock) = 0; + + // processSocketReadEvent() tells the server there is a Socket write event. + // This is only necessary if the Socket has been put in non-blocking + // mode and needs this callback to flush the buffer. + virtual void processSocketWriteEvent(network::Socket* sock) = 0; + // blockUpdates()/unblockUpdates() tells the server that the pixel buffer // is currently in flux and may not be accessed. The attributes of the // pixel buffer may still be accessed, but not the frame buffer itself. diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index c97b0735..edf23a4f 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -55,6 +55,8 @@ #include #include +#include + #include #include #include @@ -128,7 +130,7 @@ VNCServerST::~VNCServerST() } -// SocketServer methods +// VNCServer methods void VNCServerST::addSocket(network::Socket* sock, bool outgoing) { @@ -233,8 +235,6 @@ void VNCServerST::processSocketWriteEvent(network::Socket* sock) throw rdr::Exception("invalid Socket in VNCServerST"); } -// VNCServer methods - void VNCServerST::blockUpdates() { blockCounter++; diff --git a/common/rfb/VNCServerST.h b/common/rfb/VNCServerST.h index f688b317..4a8efa46 100644 --- a/common/rfb/VNCServerST.h +++ b/common/rfb/VNCServerST.h @@ -51,7 +51,7 @@ namespace rfb { virtual ~VNCServerST(); - // Methods overridden from SocketServer + // Methods overridden from VNCServer // addSocket // Causes the server to allocate an RFB-protocol management @@ -76,9 +76,6 @@ namespace rfb { // Flush pending data from the Socket on to the network. virtual void processSocketWriteEvent(network::Socket* sock); - - // Methods overridden from VNCServer - virtual void blockUpdates(); virtual void unblockUpdates(); virtual void setPixelBuffer(PixelBuffer* pb, const ScreenSet& layout); diff --git a/unix/x0vncserver/XDesktop.cxx b/unix/x0vncserver/XDesktop.cxx index b3d5e54c..da298d35 100644 --- a/unix/x0vncserver/XDesktop.cxx +++ b/unix/x0vncserver/XDesktop.cxx @@ -26,6 +26,8 @@ #include #include +#include + #include #include diff --git a/unix/xserver/hw/vnc/XserverDesktop.cc b/unix/xserver/hw/vnc/XserverDesktop.cc index b5a58671..a2160a72 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.cc +++ b/unix/xserver/hw/vnc/XserverDesktop.cc @@ -311,7 +311,7 @@ void XserverDesktop::handleSocketEvent(int fd, bool read, bool write) bool XserverDesktop::handleListenerEvent(int fd, std::list* sockets, - SocketServer* sockserv) + VNCServer* sockserv) { std::list::iterator i; @@ -332,7 +332,7 @@ bool XserverDesktop::handleListenerEvent(int fd, } bool XserverDesktop::handleSocketEvent(int fd, - SocketServer* sockserv, + VNCServer* sockserv, bool read, bool write) { std::list sockets; diff --git a/unix/xserver/hw/vnc/XserverDesktop.h b/unix/xserver/hw/vnc/XserverDesktop.h index 677097a6..a42b5440 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.h +++ b/unix/xserver/hw/vnc/XserverDesktop.h @@ -42,7 +42,7 @@ namespace rfb { class VNCServerST; } -namespace network { class SocketListener; class Socket; class SocketServer; } +namespace network { class SocketListener; class Socket; } class XserverDesktop : public rfb::SDesktop, public rfb::FullFramePixelBuffer, public rfb::Timer::Callback { @@ -107,9 +107,9 @@ public: protected: bool handleListenerEvent(int fd, std::list* sockets, - network::SocketServer* sockserv); + rfb::VNCServer* sockserv); bool handleSocketEvent(int fd, - network::SocketServer* sockserv, + rfb::VNCServer* sockserv, bool read, bool write); virtual bool handleTimeout(rfb::Timer* t); diff --git a/win/rfb_win32/SocketManager.cxx b/win/rfb_win32/SocketManager.cxx index b7cc1cce..8e88b79b 100644 --- a/win/rfb_win32/SocketManager.cxx +++ b/win/rfb_win32/SocketManager.cxx @@ -24,8 +24,12 @@ #include #include + +#include + #include #include +#include #include #include @@ -55,7 +59,7 @@ static void requestAddressChangeEvents(network::SocketListener* sock_) { void SocketManager::addListener(network::SocketListener* sock_, - network::SocketServer* srvr, + VNCServer* srvr, AddressChangeNotifier* acn) { WSAEVENT event = WSACreateEvent(); long flags = FD_ACCEPT | FD_CLOSE; @@ -103,7 +107,7 @@ void SocketManager::remListener(network::SocketListener* sock) { } -void SocketManager::addSocket(network::Socket* sock_, network::SocketServer* srvr, bool outgoing) { +void SocketManager::addSocket(network::Socket* sock_, VNCServer* srvr, bool outgoing) { WSAEVENT event = WSACreateEvent(); if (!event || !addEvent(event, this) || (WSAEventSelect(sock_->getFd(), event, FD_READ | FD_CLOSE) == SOCKET_ERROR)) { @@ -135,7 +139,7 @@ void SocketManager::remSocket(network::Socket* sock_) { throw rdr::Exception("Socket not registered"); } -bool SocketManager::getDisable(network::SocketServer* srvr) +bool SocketManager::getDisable(VNCServer* srvr) { std::map::iterator i; for (i=listeners.begin(); i!=listeners.end(); i++) { @@ -146,7 +150,7 @@ bool SocketManager::getDisable(network::SocketServer* srvr) throw rdr::Exception("Listener not registered"); } -void SocketManager::setDisable(network::SocketServer* srvr, bool disable) +void SocketManager::setDisable(VNCServer* srvr, bool disable) { bool found = false; std::map::iterator i; diff --git a/win/rfb_win32/SocketManager.h b/win/rfb_win32/SocketManager.h index e5ca02e6..809c470e 100644 --- a/win/rfb_win32/SocketManager.h +++ b/win/rfb_win32/SocketManager.h @@ -19,22 +19,28 @@ // -=- SocketManager.h // Socket manager class for Win32. -// Passed a network::SocketListener and a network::SocketServer when +// Passed a network::SocketListener and a rfb::VNCServer when // constructed. Uses WSAAsyncSelect to get notifications of network // connection attempts. When an incoming connection is received, -// the manager will call network::SocketServer::addClient(). If +// the manager will call rfb::VNCServer::addClient(). If // addClient returns true then the manager registers interest in // network events on that socket, and calls -// network::SocketServer::processSocketEvent(). +// rfb::VNCServer::processSocketEvent(). #ifndef __RFB_WIN32_SOCKET_MGR_H__ #define __RFB_WIN32_SOCKET_MGR_H__ #include -#include #include +namespace network { + class SocketListener; + class Socket; +} + namespace rfb { + class VNCServer; + namespace win32 { class SocketManager : public EventManager, EventHandler { @@ -52,21 +58,21 @@ namespace rfb { }; // Add a listening socket. Incoming connections will be added to the supplied - // SocketServer. + // VNCServer. void addListener(network::SocketListener* sock_, - network::SocketServer* srvr, + VNCServer* srvr, AddressChangeNotifier* acn = 0); // Remove and delete a listening socket. void remListener(network::SocketListener* sock); // Add an already-connected socket. Socket events will cause the supplied - // SocketServer to be called. The socket must ALREADY BE REGISTERED with - // the SocketServer. - void addSocket(network::Socket* sock_, network::SocketServer* srvr, bool outgoing=true); + // VNCServer to be called. The socket must ALREADY BE REGISTERED with + // the VNCServer. + void addSocket(network::Socket* sock_, VNCServer* srvr, bool outgoing=true); - bool getDisable(network::SocketServer* srvr); - void setDisable(network::SocketServer* srvr, bool disable); + bool getDisable(VNCServer* srvr); + void setDisable(VNCServer* srvr, bool disable); protected: virtual int checkTimeouts(); @@ -75,11 +81,11 @@ namespace rfb { struct ConnInfo { network::Socket* sock; - network::SocketServer* server; + VNCServer* server; }; struct ListenInfo { network::SocketListener* sock; - network::SocketServer* server; + VNCServer* server; AddressChangeNotifier* notifier; bool disable; }; diff --git a/win/winvnc/ManagedListener.cxx b/win/winvnc/ManagedListener.cxx index a93ca298..1a278678 100644 --- a/win/winvnc/ManagedListener.cxx +++ b/win/winvnc/ManagedListener.cxx @@ -45,7 +45,7 @@ ManagedListener::~ManagedListener() { } -void ManagedListener::setServer(network::SocketServer* svr) { +void ManagedListener::setServer(rfb::VNCServer* svr) { if (svr == server) return; vlog.info("set server to %p", svr); diff --git a/win/winvnc/ManagedListener.h b/win/winvnc/ManagedListener.h index 39223c79..20503c33 100644 --- a/win/winvnc/ManagedListener.h +++ b/win/winvnc/ManagedListener.h @@ -27,7 +27,7 @@ namespace winvnc { // -=- ManagedListener // Wrapper class which simplifies the management of a listening socket - // on a specified port, attached to a SocketManager and SocketServer. + // on a specified port, attached to a SocketManager and VNCServer. // Reopens sockets & reconfigures filters & callbacks as appropriate. // Handles addition/removal of Listeners from SocketManager internally. @@ -36,7 +36,7 @@ namespace winvnc { ManagedListener(rfb::win32::SocketManager* mgr); ~ManagedListener(); - void setServer(network::SocketServer* svr); + void setServer(rfb::VNCServer* svr); void setPort(int port, bool localOnly=false); void setFilter(const char* filter); void setAddressChangeNotifier(rfb::win32::SocketManager::AddressChangeNotifier* acn); @@ -49,7 +49,7 @@ namespace winvnc { network::TcpFilter* filter; rfb::win32::SocketManager* manager; rfb::win32::SocketManager::AddressChangeNotifier* addrChangeNotifier; - network::SocketServer* server; + rfb::VNCServer* server; int port; bool localOnly; }; -- 2.39.5