2 * FreeRDP: A Remote Desktop Protocol Client
5 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
25 #include <X11/Xutil.h>
26 #include <sys/select.h>
27 #include <sys/signal.h>
29 #include <freerdp/utils/memory.h>
34 char* xf_pcap_file = NULL;
35 boolean xf_pcap_dump_realtime = true;
37 void xf_server_main_loop(freerdp_listener* instance)
46 memset(rfds, 0, sizeof(rfds));
52 if (instance->GetFileDescriptor(instance, rfds, &rcount) != true)
54 printf("Failed to get FreeRDP file descriptor\n");
61 for (i = 0; i < rcount; i++)
63 fds = (int)(long)(rfds[i]);
68 FD_SET(fds, &rfds_set);
74 if (select(max_fds + 1, &rfds_set, NULL, NULL, NULL) == -1)
76 /* these are not really errors */
77 if (!((errno == EAGAIN) ||
78 (errno == EWOULDBLOCK) ||
79 (errno == EINPROGRESS) ||
80 (errno == EINTR))) /* signal occurred */
82 printf("select failed\n");
87 if (instance->CheckFileDescriptor(instance) != true)
89 printf("Failed to check FreeRDP file descriptor\n");
94 instance->Close(instance);
97 int main(int argc, char* argv[])
99 freerdp_listener* instance;
101 /* ignore SIGPIPE, otherwise an SSL_write failure could crash the server */
102 signal(SIGPIPE, SIG_IGN);
104 instance = freerdp_listener_new();
105 instance->PeerAccepted = xf_peer_accepted;
108 xf_pcap_file = argv[1];
110 if (argc > 2 && !strcmp(argv[2], "--fast"))
111 xf_pcap_dump_realtime = false;
113 /* Open the server socket and start listening. */
114 if (instance->Open(instance, NULL, 3389))
116 /* Entering the server main loop. In a real server the listener can be run in its own thread. */
117 xf_server_main_loop(instance);
120 freerdp_listener_free(instance);