blob: 212ae076475378b8d999ea8ef1dffb5e511065cb [file] [log] [blame]
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 * Copyright (C) 2004-2006 Constantin Kaplinsky. All Rights Reserved.
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00003 *
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this software; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
18 */
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000019
20// FIXME: Check cases when screen width/height is not a multiply of 32.
21// e.g. 800x600.
22
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000023#include <strings.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000024#include <sys/types.h>
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000025#include <sys/stat.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000026#include <unistd.h>
27#include <errno.h>
28#include <rfb/Logger_stdio.h>
29#include <rfb/LogWriter.h>
30#include <rfb/VNCServerST.h>
31#include <rfb/Configuration.h>
32#include <rfb/SSecurityFactoryStandard.h>
33
34#include <network/TcpSocket.h>
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +000035#include <tx/TXWindow.h>
36
Constantin Kaplinsky3f6ad6b2006-04-17 14:06:41 +000037#include <vncconfig_unix/QueryConnectDialog.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000038
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000039#include <signal.h>
40#include <X11/X.h>
41#include <X11/Xlib.h>
42#include <X11/Xutil.h>
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000043#ifdef HAVE_XTEST
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000044#include <X11/extensions/XTest.h>
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000045#endif
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000046
Constantin Kaplinskyaf1891c2005-09-29 06:18:28 +000047#include <x0vncserver/Image.h>
48#include <x0vncserver/PollingManager.h>
Constantin Kaplinsky0cbad332006-02-16 14:51:11 +000049#include <x0vncserver/PollingScheduler.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000050
Constantin Kaplinskya6866902006-03-02 12:03:30 +000051// XXX Lynx/OS 2.3: protos for select(), bzero()
52#ifdef Lynx
53#include <sys/proto.h>
54#endif
55
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000056using namespace rfb;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000057using namespace network;
58
59LogWriter vlog("main");
60
Constantin Kaplinsky602f34d2005-09-14 16:11:41 +000061IntParameter pollingCycle("PollingCycle", "Milliseconds per one polling "
62 "cycle; actual interval may be dynamically "
Constantin Kaplinskyef7ac9b2006-02-10 12:26:54 +000063 "adjusted to satisfy MaxProcessorUsage setting", 30);
Constantin Kaplinsky602f34d2005-09-14 16:11:41 +000064IntParameter maxProcessorUsage("MaxProcessorUsage", "Maximum percentage of "
65 "CPU time to be consumed", 35);
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000066BoolParameter useShm("UseSHM", "Use MIT-SHM extension if available", true);
67BoolParameter useOverlay("OverlayMode", "Use overlay mode under "
68 "IRIX or Solaris", true);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000069StringParameter displayname("display", "The X display", "");
70IntParameter rfbport("rfbport", "TCP port to listen for RFB protocol",5900);
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +000071IntParameter queryConnectTimeout("QueryConnectTimeout",
72 "Number of seconds to show the Accept Connection dialog before "
73 "rejecting the connection",
74 10);
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000075StringParameter hostsFile("HostsFile", "File with IP access control rules", "");
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000076
77static void CleanupSignalHandler(int sig)
78{
79 // CleanupSignalHandler allows C++ object cleanup to happen because it calls
80 // exit() rather than the default which is to abort.
81 fprintf(stderr,"CleanupSignalHandler called\n");
82 exit(1);
83}
84
85
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +000086class QueryConnHandler : public VNCServerST::QueryConnectionHandler,
87 public QueryResultCallback {
88public:
89 QueryConnHandler(Display* dpy, VNCServerST* vs)
90 : display(dpy), server(vs), queryConnectDialog(0), queryConnectSock(0) {}
91 ~QueryConnHandler() { delete queryConnectDialog; }
92
93 // -=- VNCServerST::QueryConnectionHandler interface
94 virtual VNCServerST::queryResult queryConnection(network::Socket* sock,
95 const char* userName,
96 char** reason) {
97 if (queryConnectSock) {
98 *reason = strDup("Another connection is currently being queried.");
99 return VNCServerST::REJECT;
100 }
101 if (!userName) userName = "(anonymous)";
102 queryConnectSock = sock;
103 CharArray address(sock->getPeerAddress());
104 delete queryConnectDialog;
105 queryConnectDialog = new QueryConnectDialog(display, address.buf,
106 userName, queryConnectTimeout,
107 this);
108 queryConnectDialog->map();
109 return VNCServerST::PENDING;
110 }
111
112 // -=- QueryResultCallback interface
113 virtual void queryApproved() {
114 server->approveConnection(queryConnectSock, true, 0);
115 queryConnectSock = 0;
116 }
117 virtual void queryRejected() {
118 server->approveConnection(queryConnectSock, false,
119 "Connection rejected by local user");
120 queryConnectSock = 0;
121 }
122private:
123 Display* display;
124 VNCServerST* server;
125 QueryConnectDialog* queryConnectDialog;
126 network::Socket* queryConnectSock;
127};
128
129
130class XDesktop : public SDesktop, public ColourMap
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000131{
132public:
133 XDesktop(Display* dpy_)
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +0000134 : dpy(dpy_), pb(0), server(0), image(0), pollmgr(0),
135 oldButtonMask(0), haveXtest(false), maxButtons(0)
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000136 {
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000137#ifdef HAVE_XTEST
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000138 int xtestEventBase;
139 int xtestErrorBase;
140 int major, minor;
141
142 if (XTestQueryExtension(dpy, &xtestEventBase,
143 &xtestErrorBase, &major, &minor)) {
144 XTestGrabControl(dpy, True);
145 vlog.info("XTest extension present - version %d.%d",major,minor);
146 haveXtest = true;
147 } else {
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000148#endif
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000149 vlog.info("XTest extension not present");
150 vlog.info("unable to inject events or display while server is grabbed");
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000151#ifdef HAVE_XTEST
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000152 }
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000153#endif
154
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +0000155 }
156 virtual ~XDesktop() {
157 stop();
158 }
159
160 // -=- SDesktop interface
161
162 virtual void start(VNCServer* vs) {
163
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000164 // Determine actual number of buttons of the X pointer device.
165 unsigned char btnMap[8];
166 int numButtons = XGetPointerMapping(dpy, btnMap, 8);
167 maxButtons = (numButtons > 8) ? 8 : numButtons;
168 vlog.info("Enabling %d button%s of X pointer device",
169 maxButtons, (maxButtons != 1) ? "s" : "");
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000170
171 int dpyWidth = DisplayWidth(dpy, DefaultScreen(dpy));
172 int dpyHeight = DisplayHeight(dpy, DefaultScreen(dpy));
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000173
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000174 ImageFactory factory((bool)useShm, (bool)useOverlay);
175 image = factory.newImage(dpy, dpyWidth, dpyHeight);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000176 image->get(DefaultRootWindow(dpy));
177
Constantin Kaplinskyaf1891c2005-09-29 06:18:28 +0000178 pollmgr = new PollingManager(dpy, image, &factory);
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +0000179 pollmgr->setVNCServer(vs);
Constantin Kaplinskyaf1891c2005-09-29 06:18:28 +0000180
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000181 pf.bpp = image->xim->bits_per_pixel;
182 pf.depth = image->xim->depth;
183 pf.bigEndian = (image->xim->byte_order == MSBFirst);
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000184 pf.trueColour = image->isTrueColor();
185 pf.redShift = ffs(image->xim->red_mask) - 1;
186 pf.greenShift = ffs(image->xim->green_mask) - 1;
187 pf.blueShift = ffs(image->xim->blue_mask) - 1;
188 pf.redMax = image->xim->red_mask >> pf.redShift;
189 pf.greenMax = image->xim->green_mask >> pf.greenShift;
190 pf.blueMax = image->xim->blue_mask >> pf.blueShift;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000191
192 pb = new FullFramePixelBuffer(pf, dpyWidth, dpyHeight,
193 (rdr::U8*)image->xim->data, this);
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +0000194 server = vs;
195 server->setPixelBuffer(pb);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000196 }
197
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +0000198 virtual void stop() {
199 delete pb;
200 delete pollmgr;
201 // FIXME: Delete images as well?!
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000202 }
203
Constantin Kaplinskyaf1891c2005-09-29 06:18:28 +0000204 inline void poll() {
205 pollmgr->poll();
206 }
207
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +0000208 virtual void pointerEvent(const Point& pos, int buttonMask) {
Constantin Kaplinskyce676c62006-02-08 13:36:58 +0000209 pollmgr->setPointerPos(pos);
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000210#ifdef HAVE_XTEST
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000211 if (!haveXtest) return;
212 XTestFakeMotionEvent(dpy, DefaultScreen(dpy), pos.x, pos.y, CurrentTime);
213 if (buttonMask != oldButtonMask) {
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000214 for (int i = 0; i < maxButtons; i++) {
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000215 if ((buttonMask ^ oldButtonMask) & (1<<i)) {
216 if (buttonMask & (1<<i)) {
217 XTestFakeButtonEvent(dpy, i+1, True, CurrentTime);
218 } else {
219 XTestFakeButtonEvent(dpy, i+1, False, CurrentTime);
220 }
221 }
222 }
223 }
224 oldButtonMask = buttonMask;
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000225#endif
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000226 }
227
228 virtual void keyEvent(rdr::U32 key, bool down) {
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000229#ifdef HAVE_XTEST
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000230 if (!haveXtest) return;
231 int keycode = XKeysymToKeycode(dpy, key);
232 if (keycode)
233 XTestFakeKeyEvent(dpy, keycode, down, CurrentTime);
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000234#endif
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000235 }
236
237 virtual void clientCutText(const char* str, int len) {
238 }
239
240 virtual Point getFbSize() {
241 return Point(pb->width(), pb->height());
242 }
243
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +0000244 // -=- ColourMap callbacks
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000245 virtual void lookup(int index, int* r, int* g, int* b) {
246 XColor xc;
247 xc.pixel = index;
248 if (index < DisplayCells(dpy,DefaultScreen(dpy))) {
249 XQueryColor(dpy, DefaultColormap(dpy,DefaultScreen(dpy)), &xc);
250 } else {
251 xc.red = xc.green = xc.blue = 0;
252 }
253 *r = xc.red;
254 *g = xc.green;
255 *b = xc.blue;
256 }
257
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000258protected:
259 Display* dpy;
260 PixelFormat pf;
261 PixelBuffer* pb;
262 VNCServer* server;
263 Image* image;
Constantin Kaplinskyaf1891c2005-09-29 06:18:28 +0000264 PollingManager* pollmgr;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000265 int oldButtonMask;
266 bool haveXtest;
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000267 int maxButtons;
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000268};
269
270
271class FileTcpFilter : public TcpFilter
272{
273
274public:
275
276 FileTcpFilter(const char *fname)
277 : TcpFilter("-"), fileName(NULL), lastModTime(0)
278 {
279 if (fname != NULL)
280 fileName = strdup((char *)fname);
281 }
282
283 virtual ~FileTcpFilter()
284 {
285 if (fileName != NULL)
286 free(fileName);
287 }
288
289 virtual bool verifyConnection(Socket* s)
290 {
291 if (!reloadRules()) {
292 vlog.error("Could not read IP filtering rules: rejecting all clients");
293 filter.clear();
294 filter.push_back(parsePattern("-"));
295 return false;
296 }
297
298 return TcpFilter::verifyConnection(s);
299 }
300
301protected:
302
303 bool reloadRules()
304 {
305 if (fileName == NULL)
306 return true;
307
308 struct stat st;
309 if (stat(fileName, &st) != 0)
310 return false;
311
312 if (st.st_mtime != lastModTime) {
313 // Actually reload only if the file was modified
314 FILE *fp = fopen(fileName, "r");
315 if (fp == NULL)
316 return false;
317
318 // Remove all the rules from the parent class
319 filter.clear();
320
321 // Parse the file contents adding rules to the parent class
322 char buf[32];
323 while (readLine(buf, 32, fp)) {
324 if (buf[0] && strchr("+-?", buf[0])) {
325 filter.push_back(parsePattern(buf));
326 }
327 }
328
329 fclose(fp);
330 lastModTime = st.st_mtime;
331 }
332 return true;
333 }
334
335protected:
336
337 char *fileName;
338 time_t lastModTime;
339
340private:
341
342 //
343 // NOTE: we silently truncate long lines in this function.
344 //
345
346 bool readLine(char *buf, int bufSize, FILE *fp)
347 {
348 if (fp == NULL || buf == NULL || bufSize == 0)
349 return false;
350
351 if (fgets(buf, bufSize, fp) == NULL)
352 return false;
353
354 char *ptr = strchr(buf, '\n');
355 if (ptr != NULL) {
356 *ptr = '\0'; // remove newline at the end
357 } else {
358 if (!feof(fp)) {
359 int c;
360 do { // skip the rest of a long line
361 c = getc(fp);
362 } while (c != '\n' && c != EOF);
363 }
364 }
365 return true;
366 }
367
368};
369
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000370char* programName;
371
372static void usage()
373{
374 fprintf(stderr, "\nusage: %s [<parameters>]\n", programName);
375 fprintf(stderr,"\n"
376 "Parameters can be turned on with -<param> or off with -<param>=0\n"
377 "Parameters which take a value can be specified as "
378 "-<param> <value>\n"
379 "Other valid forms are <param>=<value> -<param>=<value> "
380 "--<param>=<value>\n"
381 "Parameter names are case-insensitive. The parameters are:\n\n");
382 Configuration::listParams(79, 14);
383 exit(1);
384}
385
386int main(int argc, char** argv)
387{
388 initStdIOLoggers();
389 LogWriter::setLogParams("*:stderr:30");
390
391 programName = argv[0];
392 Display* dpy;
393
394 for (int i = 1; i < argc; i++) {
395 if (Configuration::setParam(argv[i]))
396 continue;
397
398 if (argv[i][0] == '-') {
399 if (i+1 < argc) {
400 if (Configuration::setParam(&argv[i][1], argv[i+1])) {
401 i++;
402 continue;
403 }
404 }
405 usage();
406 }
407
408 usage();
409 }
410
411 CharArray dpyStr(displayname.getData());
412 if (!(dpy = XOpenDisplay(dpyStr.buf[0] ? dpyStr.buf : 0))) {
413 fprintf(stderr,"%s: unable to open display \"%s\"\r\n",
414 programName, XDisplayName(displayname.getData()));
415 exit(1);
416 }
417
418 signal(SIGHUP, CleanupSignalHandler);
419 signal(SIGINT, CleanupSignalHandler);
420 signal(SIGTERM, CleanupSignalHandler);
421
422 try {
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +0000423 TXWindow::init(dpy,"x0vncserver");
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000424 XDesktop desktop(dpy);
425 VNCServerST server("x0vncserver", &desktop);
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +0000426 QueryConnHandler qcHandler(dpy, &server);
427 server.setQueryConnectionHandler(&qcHandler);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000428
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000429 TcpListener listener((int)rfbport);
430 vlog.info("Listening on port %d", (int)rfbport);
431
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000432 FileTcpFilter fileTcpFilter(hostsFile.getData());
433 if (strlen(hostsFile.getData()) != 0)
434 listener.setFilter(&fileTcpFilter);
435
Constantin Kaplinskye179b5a2006-02-17 09:30:21 +0000436 PollingScheduler sched((int)pollingCycle, (int)maxProcessorUsage);
Constantin Kaplinsky602f34d2005-09-14 16:11:41 +0000437
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000438 while (true) {
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +0000439 struct timeval tv;
440 fd_set rfds;
441 std::list<Socket*> sockets;
442 std::list<Socket*>::iterator i;
443
444 // Process any incoming X events
445 TXWindow::handleXEvents(dpy);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000446
447 FD_ZERO(&rfds);
448 FD_SET(listener.getFd(), &rfds);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000449 server.getSockets(&sockets);
Constantin Kaplinsky3f56fa72006-02-16 11:50:25 +0000450 int clients_connected = 0;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000451 for (i = sockets.begin(); i != sockets.end(); i++) {
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +0000452 if ((*i)->isShutdown()) {
453 server.removeSocket(*i);
454 delete (*i);
455 } else {
456 FD_SET((*i)->getFd(), &rfds);
457 clients_connected++;
458 }
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000459 }
460
Constantin Kaplinsky3f56fa72006-02-16 11:50:25 +0000461 if (clients_connected) {
Constantin Kaplinsky0cbad332006-02-16 14:51:11 +0000462 int wait_ms = sched.millisRemaining();
463 if (wait_ms > 500) {
Constantin Kaplinsky3f56fa72006-02-16 11:50:25 +0000464 wait_ms = 500;
465 }
466 tv.tv_usec = wait_ms * 1000;
467#ifdef DEBUG
Constantin Kaplinsky6a34ca52006-02-17 11:29:17 +0000468 // fprintf(stderr, "[%d]\t", wait_ms);
Constantin Kaplinsky3f56fa72006-02-16 11:50:25 +0000469#endif
470 } else {
Constantin Kaplinsky0cbad332006-02-16 14:51:11 +0000471 sched.reset();
472 tv.tv_usec = 100000;
Constantin Kaplinsky3f56fa72006-02-16 11:50:25 +0000473 }
474 tv.tv_sec = 0;
475
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +0000476 // Do the wait...
Constantin Kaplinskye179b5a2006-02-17 09:30:21 +0000477 sched.sleepStarted();
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000478 int n = select(FD_SETSIZE, &rfds, 0, 0, &tv);
Constantin Kaplinskye179b5a2006-02-17 09:30:21 +0000479 sched.sleepFinished();
480
Constantin Kaplinsky659e9002005-09-09 08:32:02 +0000481 if (n < 0) {
482 if (errno == EINTR) {
483 vlog.debug("interrupted select() system call");
484 continue;
485 } else {
486 throw rdr::SystemException("select", errno);
487 }
488 }
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000489
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +0000490 // Accept new VNC connections
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000491 if (FD_ISSET(listener.getFd(), &rfds)) {
492 Socket* sock = listener.accept();
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000493 if (sock) {
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +0000494 server.addSocket(sock);
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000495 } else {
496 vlog.status("Client connection rejected");
497 }
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000498 }
499
500 server.getSockets(&sockets);
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000501
502 // Nothing more to do if there are no client connections.
503 if (sockets.empty())
504 continue;
505
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +0000506 // Process events on existing VNC connections
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000507 for (i = sockets.begin(); i != sockets.end(); i++) {
Constantin Kaplinskya1d2cef2006-04-17 08:46:22 +0000508 if (FD_ISSET((*i)->getFd(), &rfds))
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000509 server.processSocketEvent(*i);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000510 }
511
512 server.checkTimeouts();
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000513
Constantin Kaplinskye47123e2006-02-16 16:44:50 +0000514 if (sched.goodTimeToPoll()) {
Constantin Kaplinsky0cbad332006-02-16 14:51:11 +0000515 sched.newPass();
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +0000516 desktop.poll();
517 }
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000518 }
519
520 } catch (rdr::Exception &e) {
521 vlog.error(e.str());
522 };
523
524 return 0;
525}