Skip to content

Commit

Permalink
Remove the network::SocketServer interface.
Browse files Browse the repository at this point in the history
Move these RFB specific things to rfb::VNCServer, for clarity.

Signed-off-by: Pierre Ossman <[email protected]>
Signed-off-by: Carlos Santos <[email protected]>
  • Loading branch information
casantos committed Apr 26, 2024
1 parent ae81801 commit d77e2b0
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 72 deletions.
35 changes: 0 additions & 35 deletions common/network/Socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<network::Socket*>* 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__
37 changes: 33 additions & 4 deletions common/rfb/VNCServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,46 @@
#ifndef __RFB_VNCSERVER_H__
#define __RFB_VNCSERVER_H__

#include <network/Socket.h>

#include <rfb/UpdateTracker.h>
#include <rfb/SSecurity.h>
#include <rfb/ScreenSet.h>

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<network::Socket*>* 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.
Expand Down
6 changes: 3 additions & 3 deletions common/rfb/VNCServerST.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
#include <assert.h>
#include <stdlib.h>

#include <network/Socket.h>

#include <rfb/ComparingUpdateTracker.h>
#include <rfb/Exception.h>
#include <rfb/KeyRemapper.h>
Expand Down Expand Up @@ -128,7 +130,7 @@ VNCServerST::~VNCServerST()
}


// SocketServer methods
// VNCServer methods

void VNCServerST::addSocket(network::Socket* sock, bool outgoing)
{
Expand Down Expand Up @@ -233,8 +235,6 @@ void VNCServerST::processSocketWriteEvent(network::Socket* sock)
throw rdr::Exception("invalid Socket in VNCServerST");
}

// VNCServer methods

void VNCServerST::blockUpdates()
{
blockCounter++;
Expand Down
5 changes: 1 addition & 4 deletions common/rfb/VNCServerST.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions unix/x0vncserver/XDesktop.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <signal.h>
#include <unistd.h>

#include <network/Socket.h>

#include <rfb/LogWriter.h>
#include <rfb/Exception.h>

Expand Down
4 changes: 2 additions & 2 deletions unix/xserver/hw/vnc/XserverDesktop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ void XserverDesktop::handleSocketEvent(int fd, bool read, bool write)

bool XserverDesktop::handleListenerEvent(int fd,
std::list<SocketListener*>* sockets,
SocketServer* sockserv)
VNCServer* sockserv)
{
std::list<SocketListener*>::iterator i;

Expand All @@ -332,7 +332,7 @@ bool XserverDesktop::handleListenerEvent(int fd,
}

bool XserverDesktop::handleSocketEvent(int fd,
SocketServer* sockserv,
VNCServer* sockserv,
bool read, bool write)
{
std::list<Socket*> sockets;
Expand Down
6 changes: 3 additions & 3 deletions unix/xserver/hw/vnc/XserverDesktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -107,9 +107,9 @@ class XserverDesktop : public rfb::SDesktop, public rfb::FullFramePixelBuffer,
protected:
bool handleListenerEvent(int fd,
std::list<network::SocketListener*>* 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);
Expand Down
12 changes: 8 additions & 4 deletions win/rfb_win32/SocketManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@

#include <winsock2.h>
#include <list>

#include <network/Socket.h>

#include <rfb/LogWriter.h>
#include <rfb/Timer.h>
#include <rfb/VNCServer.h>
#include <rfb/util.h>
#include <rfb_win32/SocketManager.h>

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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<HANDLE,ListenInfo>::iterator i;
for (i=listeners.begin(); i!=listeners.end(); i++) {
Expand All @@ -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<HANDLE,ListenInfo>::iterator i;
Expand Down
32 changes: 19 additions & 13 deletions win/rfb_win32/SocketManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <map>
#include <network/Socket.h>
#include <rfb_win32/EventManager.h>

namespace network {
class SocketListener;
class Socket;
}

namespace rfb {
class VNCServer;

namespace win32 {

class SocketManager : public EventManager, EventHandler {
Expand All @@ -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();
Expand All @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion win/winvnc/ManagedListener.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions win/winvnc/ManagedListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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);
Expand All @@ -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;
};
Expand Down

0 comments on commit d77e2b0

Please sign in to comment.