2 * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
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.
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.
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,
21 * listen.c - listen for incoming connections
24 #ifdef __STRICT_ANSI__
28 #include <sys/types.h>
33 #include <sys/utsname.h>
36 #include <rfb/rfbclient.h>
39 * listenForIncomingConnections() - listen for incoming connections from
40 * servers, and fork a new process to deal with each connection.
44 listenForIncomingConnections(rfbClient* client)
48 rfbClientErr("listenForIncomingConnections on MinGW32 NOT IMPLEMENTED\n");
54 client->listenSpecified = TRUE;
56 listenSocket = ListenAtTcpPort(client->listenPort);
58 if ((listenSocket < 0))
61 rfbClientLog("Listening on port %d\n",
63 rfbClientLog("Command line errors are not reported until "
64 "a connection comes in.\n");
66 while (client->listenSpecified) {
68 /* reap any zombies */
70 while ((pid= wait3(&status, WNOHANG, (struct rusage *)0))>0);
72 /* TODO: callback for discard any events (like X11 events) */
76 FD_SET(listenSocket, &fds);
79 struct timeval timeout;
81 timeout.tv_usec=100000;
83 select(FD_SETSIZE, &fds, NULL, NULL, &timeout);
85 if (FD_ISSET(listenSocket, &fds)) {
86 client->sock = AcceptTcpConnection(listenSocket);
89 if (!SetNonBlocking(client->sock))
92 //modified to accept only a single connection
93 //if something goes wrong, we can always create another listening socket
94 rfbClientLog("Accepted connection.\n");