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("%s -listen: Listening on port %d\n",
62 client->programName,client->listenPort);
63 rfbClientLog("%s -listen: Command line errors are not reported until "
64 "a connection comes in.\n", client->programName);
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);
78 select(FD_SETSIZE, &fds, NULL, NULL, NULL);
80 if (FD_ISSET(listenSocket, &fds)) {
81 client->sock = AcceptTcpConnection(listenSocket);
84 if (!SetNonBlocking(client->sock))
87 /* Now fork off a new process to deal with it... */
92 rfbClientErr("fork\n");
96 /* child - return to caller */
101 /* parent - go round and listen again */