From 729814fabd2016aeb558457cfc53bffb95c3fef5 Mon Sep 17 00:00:00 2001 From: Norbert Federa Date: Mon, 24 Jun 2013 18:02:21 +0200 Subject: [PATCH] sample server: support build on win32 --- server/CMakeLists.txt | 8 ++++---- server/Sample/sfreerdp.c | 42 +++++++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 265706ba5..fed64d78c 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -19,11 +19,11 @@ add_subdirectory(common) -if(NOT WIN32) - if(WITH_SAMPLE) - add_subdirectory(Sample) - endif() +if(WITH_SAMPLE) + add_subdirectory(Sample) +endif() +if(NOT WIN32) if(WITH_X11) add_subdirectory(X11) endif() diff --git a/server/Sample/sfreerdp.c b/server/Sample/sfreerdp.c index afd83f4f8..952b7218f 100644 --- a/server/Sample/sfreerdp.c +++ b/server/Sample/sfreerdp.c @@ -26,14 +26,13 @@ #include #include #include -#include #include -#include #include #include #include +#include #include #include "sf_audin.h" @@ -41,7 +40,7 @@ #include "sfreerdp.h" -#define SAMPLE_SERVER_USE_CLIENT_RESOLUTION 0 +#define SAMPLE_SERVER_USE_CLIENT_RESOLUTION 1 #define SAMPLE_SERVER_DEFAULT_WIDTH 1024 #define SAMPLE_SERVER_DEFAULT_HEIGHT 768 @@ -569,9 +568,11 @@ void tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) } else { - client->settings->DesktopWidth = 640; - client->settings->DesktopHeight = 480; + client->settings->DesktopWidth = SAMPLE_SERVER_DEFAULT_WIDTH; + client->settings->DesktopHeight = SAMPLE_SERVER_DEFAULT_HEIGHT; } + context->rfx_context->width = client->settings->DesktopWidth; + context->rfx_context->height = client->settings->DesktopHeight; update->DesktopResize(update->context); context->activated = FALSE; } @@ -698,7 +699,11 @@ static void* test_peer_mainloop(void* arg) printf("Failed to get FreeRDP file descriptor\n"); break; } + +#ifndef _WIN32 + /* winsock's select() only works with sockets ! */ WTSVirtualChannelManagerGetFileDescriptor(context->vcm, rfds, &rcount); +#endif max_fds = 0; FD_ZERO(&rfds_set); @@ -718,15 +723,27 @@ static void* test_peer_mainloop(void* arg) if (select(max_fds + 1, &rfds_set, NULL, NULL, NULL) == -1) { +#ifdef _WIN32 + /* error codes set by windows sockets are not made available through errno ! */ + int wsa_error = WSAGetLastError(); + if (!((wsa_error == WSAEWOULDBLOCK) || + (wsa_error == WSAEINPROGRESS) || + (wsa_error == WSAEINTR))) + { + printf("select failed (WSAGetLastError: %d)\n", wsa_error); + break; + } +#else /* these are not really errors */ if (!((errno == EAGAIN) || (errno == EWOULDBLOCK) || (errno == EINPROGRESS) || (errno == EINTR))) /* signal occurred */ { - printf("select failed\n"); + printf("select failed (errno: %d)\n", errno); break; } +#endif } if (client->CheckFileDescriptor(client) != TRUE) @@ -747,10 +764,10 @@ static void* test_peer_mainloop(void* arg) static void test_peer_accepted(freerdp_listener* instance, freerdp_peer* client) { - pthread_t th; - - pthread_create(&th, 0, test_peer_mainloop, client); - pthread_detach(th); + HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) test_peer_mainloop, (void*) client, 0, NULL); + if (hThread != NULL) { + CloseHandle(hThread); + } } static void test_server_mainloop(freerdp_listener* instance) @@ -817,9 +834,6 @@ int main(int argc, char* argv[]) { freerdp_listener* instance; - /* Ignore SIGPIPE, otherwise an SSL_write failure could crash your server */ - signal(SIGPIPE, SIG_IGN); - instance = freerdp_listener_new(); instance->PeerAccepted = test_peer_accepted; @@ -831,12 +845,14 @@ int main(int argc, char* argv[]) test_dump_rfx_realtime = FALSE; /* Open the server socket and start listening. */ + freerdp_wsa_startup(); if (instance->Open(instance, NULL, 3389) && instance->OpenLocal(instance, "/tmp/tfreerdp-server.0")) { /* Entering the server main loop. In a real server the listener can be run in its own thread. */ test_server_mainloop(instance); } + freerdp_wsa_cleanup(); freerdp_listener_free(instance);