mirror of
https://github.com/FreeRDP/FreeRDP.git
synced 2024-11-27 03:44:06 +08:00
wfreerdp: fix mutex handling
This commit is contained in:
parent
123398c419
commit
5de4cdbedc
@ -52,6 +52,11 @@ if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
|
||||
set(CMAKE_INSTALL_LIBDIR "lib")
|
||||
endif()
|
||||
|
||||
# Set default bindir
|
||||
if(NOT DEFINED CMAKE_INSTALL_BINDIR)
|
||||
set(CMAKE_INSTALL_BINDIR "bin")
|
||||
endif()
|
||||
|
||||
# build shared libs
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
set(BUILD_SHARED_LIBS ON)
|
||||
@ -80,6 +85,8 @@ if(MSVC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFREERDP_EXPORTS")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWIN32_LEAN_AND_MEAN")
|
||||
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
|
||||
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
# Include files
|
||||
|
@ -32,4 +32,4 @@ target_link_libraries(dfreerdp freerdp-chanman)
|
||||
target_link_libraries(dfreerdp freerdp-utils)
|
||||
target_link_libraries(dfreerdp ${DIRECTFB_LIBRARIES})
|
||||
|
||||
install(TARGETS dfreerdp DESTINATION bin)
|
||||
install(TARGETS dfreerdp DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
@ -25,3 +25,5 @@ target_link_libraries(wfreerdp freerdp-core)
|
||||
target_link_libraries(wfreerdp freerdp-gdi)
|
||||
target_link_libraries(wfreerdp freerdp-utils)
|
||||
target_link_libraries(wfreerdp freerdp-chanman)
|
||||
|
||||
install(TARGETS wfreerdp DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
@ -89,8 +89,6 @@ boolean wf_pre_connect(freerdp* instance)
|
||||
settings->order_support[NEG_ELLIPSE_CB_INDEX] = False;
|
||||
|
||||
settings->kbd_layout = (int) GetKeyboardLayout(0) & 0x0000FFFF;
|
||||
printf("keyboard_layout: 0x%X\n", settings->kbd_layout);
|
||||
|
||||
freerdp_chanman_pre_connect(GET_CHANMAN(instance), instance);
|
||||
|
||||
return True;
|
||||
@ -142,6 +140,21 @@ boolean wf_check_fds(freerdp* instance)
|
||||
return True;
|
||||
}
|
||||
|
||||
int wf_process_plugin_args(rdpSettings* settings, const char* name, RDP_PLUGIN_DATA* plugin_data, void* user_data)
|
||||
{
|
||||
rdpChanMan* chanman = (rdpChanMan*) user_data;
|
||||
|
||||
printf("loading plugin %s\n", name);
|
||||
freerdp_chanman_load_plugin(chanman, settings, name, plugin_data);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int wf_process_ui_args(rdpSettings* settings, const char* opt, const char* val, void* user_data)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wfreerdp_run(freerdp* instance)
|
||||
{
|
||||
MSG msg;
|
||||
@ -156,6 +169,12 @@ int wfreerdp_run(freerdp* instance)
|
||||
HANDLE fds[64];
|
||||
rdpChanMan* chanman;
|
||||
|
||||
memset(rfds, 0, sizeof(rfds));
|
||||
memset(wfds, 0, sizeof(wfds));
|
||||
|
||||
if (!instance->Connect(instance))
|
||||
return 0;
|
||||
|
||||
chanman = GET_CHANMAN(instance);
|
||||
|
||||
/* program main loop */
|
||||
@ -169,16 +188,16 @@ int wfreerdp_run(freerdp* instance)
|
||||
printf("Failed to get FreeRDP file descriptor\n");
|
||||
break;
|
||||
}
|
||||
if (freerdp_chanman_get_fds(chanman, instance, rfds, &rcount, wfds, &wcount) != True)
|
||||
{
|
||||
printf("Failed to get channel manager file descriptor\n");
|
||||
break;
|
||||
}
|
||||
if (wf_get_fds(instance, rfds, &rcount, wfds, &wcount) != True)
|
||||
{
|
||||
printf("Failed to get wfreerdp file descriptor\n");
|
||||
break;
|
||||
}
|
||||
if (freerdp_chanman_get_fds(chanman, instance, rfds, &rcount, wfds, &wcount) != True)
|
||||
{
|
||||
printf("Failed to get channel manager file descriptor\n");
|
||||
break;
|
||||
}
|
||||
|
||||
fds_count = 0;
|
||||
/* setup read fds */
|
||||
@ -200,7 +219,7 @@ int wfreerdp_run(freerdp* instance)
|
||||
/* do the wait */
|
||||
if (MsgWaitForMultipleObjects(fds_count, fds, FALSE, INFINITE, QS_ALLINPUT) == WAIT_FAILED)
|
||||
{
|
||||
printf("wfreerdp_run: WaitForMultipleObjects failed\n");
|
||||
printf("wfreerdp_run: WaitForMultipleObjects failed: 0x%04X\n", GetLastError());
|
||||
break;
|
||||
}
|
||||
|
||||
@ -262,6 +281,7 @@ static DWORD WINAPI thread_func(LPVOID lpParam)
|
||||
SET_WFI(instance, wfi);
|
||||
|
||||
wfreerdp_run(instance);
|
||||
|
||||
g_thread_count--;
|
||||
|
||||
if (g_thread_count < 1)
|
||||
@ -337,6 +357,7 @@ INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
RegisterClassEx(&wnd_cls);
|
||||
|
||||
g_hInstance = hInstance;
|
||||
freerdp_chanman_global_init();
|
||||
|
||||
instance = freerdp_new();
|
||||
instance->PreConnect = wf_pre_connect;
|
||||
@ -354,12 +375,11 @@ INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
data = (thread_data*) xzalloc(sizeof(thread_data));
|
||||
data->instance = instance;
|
||||
|
||||
freerdp_parse_args(instance->settings, __argc, __argv, NULL, NULL, NULL, NULL);
|
||||
freerdp_parse_args(instance->settings, __argc, __argv,
|
||||
wf_process_plugin_args, chanman, wf_process_ui_args, NULL);
|
||||
|
||||
if (CreateThread(NULL, 0, thread_func, data, 0, NULL) != 0)
|
||||
{
|
||||
g_thread_count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_thread_count > 0)
|
||||
|
@ -91,5 +91,4 @@ target_link_libraries(xfreerdp freerdp-chanman)
|
||||
target_link_libraries(xfreerdp freerdp-utils)
|
||||
target_link_libraries(xfreerdp ${X11_LIBRARIES} dl)
|
||||
|
||||
install(TARGETS xfreerdp DESTINATION bin)
|
||||
|
||||
install(TARGETS xfreerdp DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
@ -575,8 +575,8 @@ rdpChanMan* freerdp_chanman_new(void)
|
||||
|
||||
void freerdp_chanman_free(rdpChanMan * chan_man)
|
||||
{
|
||||
rdpChanManList * list;
|
||||
rdpChanManList * prev;
|
||||
rdpChanManList* list;
|
||||
rdpChanManList* prev;
|
||||
|
||||
freerdp_mutex_free(chan_man->sync_data_mutex);
|
||||
list_free(chan_man->sync_data_list);
|
||||
|
@ -108,6 +108,7 @@ boolean tcp_connect(rdpTcp* tcp, const char* hostname, uint16 port)
|
||||
struct addrinfo hints = { 0 };
|
||||
struct addrinfo * res, * ai;
|
||||
|
||||
memset(&hints, 0, sizeof(struct addrinfo));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
@ -236,7 +237,15 @@ boolean tcp_set_blocking_mode(rdpTcp* tcp, boolean blocking)
|
||||
|
||||
rdpTcp* tcp_new(rdpSettings* settings)
|
||||
{
|
||||
rdpTcp* tcp = (rdpTcp*) xzalloc(sizeof(rdpTcp));
|
||||
rdpTcp* tcp;
|
||||
|
||||
#ifdef _WIN32
|
||||
int wsaStatus;
|
||||
WSADATA wsaData;
|
||||
WORD wVersionRequested;
|
||||
#endif
|
||||
|
||||
tcp = (rdpTcp*) xzalloc(sizeof(rdpTcp));
|
||||
|
||||
if (tcp != NULL)
|
||||
{
|
||||
@ -244,6 +253,14 @@ rdpTcp* tcp_new(rdpSettings* settings)
|
||||
tcp->settings = settings;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
wVersionRequested = MAKEWORD(2, 2);
|
||||
wsaStatus = WSAStartup(wVersionRequested, &wsaData);
|
||||
|
||||
if (wsaStatus != 0)
|
||||
printf("WSAStartup failed with error: %d\n", wsaStatus);
|
||||
#endif
|
||||
|
||||
return tcp;
|
||||
}
|
||||
|
||||
|
@ -20,48 +20,42 @@
|
||||
#include <freerdp/utils/memory.h>
|
||||
#include <freerdp/utils/mutex.h>
|
||||
|
||||
#if defined _WIN32
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#define freerdp_mutex_t HANDLE
|
||||
|
||||
#else
|
||||
|
||||
#include <pthread.h>
|
||||
#define freerdp_mutex_t pthread_mutex_t
|
||||
|
||||
#endif
|
||||
|
||||
freerdp_mutex freerdp_mutex_new(void)
|
||||
{
|
||||
freerdp_mutex_t* mutex;
|
||||
|
||||
mutex = xnew(freerdp_mutex_t);
|
||||
|
||||
#if defined _WIN32
|
||||
*mutex = CreateMutex(NULL, FALSE, NULL);
|
||||
#ifdef _WIN32
|
||||
freerdp_mutex_t mutex;
|
||||
mutex = CreateMutex(NULL, FALSE, NULL);
|
||||
return (freerdp_mutex) mutex;
|
||||
#else
|
||||
freerdp_mutex_t* mutex;
|
||||
mutex = xnew(freerdp_mutex_t);
|
||||
pthread_mutex_init(mutex, 0);
|
||||
#endif
|
||||
|
||||
return mutex;
|
||||
#endif
|
||||
}
|
||||
|
||||
void freerdp_mutex_free(freerdp_mutex mutex)
|
||||
{
|
||||
#if defined _WIN32
|
||||
CloseHandle(*((freerdp_mutex_t*)mutex));
|
||||
#ifdef _WIN32
|
||||
CloseHandle((freerdp_mutex_t) mutex);
|
||||
#else
|
||||
pthread_mutex_destroy((freerdp_mutex_t*)mutex);
|
||||
#endif
|
||||
|
||||
pthread_mutex_destroy((freerdp_mutex_t*) mutex);
|
||||
xfree(mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
void freerdp_mutex_lock(freerdp_mutex mutex)
|
||||
{
|
||||
#if defined _WIN32
|
||||
WaitForSingleObject(*((freerdp_mutex_t*)mutex), INFINITE);
|
||||
#ifdef _WIN32
|
||||
WaitForSingleObject((freerdp_mutex_t) mutex, INFINITE);
|
||||
#else
|
||||
pthread_mutex_lock(mutex);
|
||||
#endif
|
||||
@ -69,8 +63,8 @@ void freerdp_mutex_lock(freerdp_mutex mutex)
|
||||
|
||||
void freerdp_mutex_unlock(freerdp_mutex mutex)
|
||||
{
|
||||
#if defined _WIN32
|
||||
ReleaseMutex(*((freerdp_mutex_t*)mutex));
|
||||
#ifdef _WIN32
|
||||
ReleaseMutex((freerdp_mutex_t) mutex);
|
||||
#else
|
||||
pthread_mutex_unlock(mutex);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user