Move these RFB specific things to rfb::VNCServer, for clarity. Signed-off-by: Pierre Ossman <ossman@cendio.se> Signed-off-by: Carlos Santos <casantos@redhat.com>pull/1670/head
@@ -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__ |
@@ -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. |
@@ -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> | |||
@@ -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++; |
@@ -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); |
@@ -26,6 +26,8 @@ | |||
#include <signal.h> | |||
#include <unistd.h> | |||
#include <network/Socket.h> | |||
#include <rfb/LogWriter.h> | |||
#include <rfb/Exception.h> | |||
@@ -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; | |||
@@ -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; |
@@ -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<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); |
@@ -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> | |||
@@ -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<HANDLE,ListenInfo>::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<HANDLE,ListenInfo>::iterator i; |
@@ -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 { | |||
@@ -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; | |||
}; |
@@ -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); |
@@ -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; | |||
}; |