From b5d9b6dba49ac2f7315d0659fa6fccec0d228deb Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 7 Feb 2019 17:26:26 +0100 Subject: [PATCH] Improved timer implementation and error messages. --- winpr/libwinpr/synch/synch.h | 1 + winpr/libwinpr/synch/timer.c | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/winpr/libwinpr/synch/synch.h b/winpr/libwinpr/synch/synch.h index 387c52b..0c48032 100644 --- a/winpr/libwinpr/synch/synch.h +++ b/winpr/libwinpr/synch/synch.h @@ -96,6 +96,7 @@ struct winpr_timer BOOL bManualReset; PTIMERAPCROUTINE pfnCompletionRoutine; LPVOID lpArgToCompletionRoutine; + char* name; #ifdef WITH_POSIX_TIMER timer_t tid; diff --git a/winpr/libwinpr/synch/timer.c b/winpr/libwinpr/synch/timer.c index 5c39d45..7034c94 100644 --- a/winpr/libwinpr/synch/timer.c +++ b/winpr/libwinpr/synch/timer.c @@ -144,6 +144,7 @@ BOOL TimerCloseHandle(HANDLE handle) close(timer->pipe[1]); #endif + free(timer->name); free(timer); return TRUE; } @@ -310,6 +311,10 @@ HANDLE CreateWaitableTimerA(LPSECURITY_ATTRIBUTES lpTimerAttributes, BOOL bManua { HANDLE handle = NULL; WINPR_TIMER* timer; + + if (lpTimerAttributes) + WLog_WARN(TAG, "%s [%s] does not support lpTimerAttributes", __FUNCTION__, lpTimerName); + timer = (WINPR_TIMER*) calloc(1, sizeof(WINPR_TIMER)); if (timer) @@ -322,6 +327,7 @@ HANDLE CreateWaitableTimerA(LPSECURITY_ATTRIBUTES lpTimerAttributes, BOOL bManua timer->pfnCompletionRoutine = NULL; timer->lpArgToCompletionRoutine = NULL; timer->bInit = FALSE; + timer->name = strdup(lpTimerName); timer->ops = &ops; #if defined(__APPLE__) @@ -375,8 +381,12 @@ HANDLE CreateWaitableTimerW(LPSECURITY_ATTRIBUTES lpTimerAttributes, BOOL bManua HANDLE CreateWaitableTimerExA(LPSECURITY_ATTRIBUTES lpTimerAttributes, LPCSTR lpTimerName, DWORD dwFlags, DWORD dwDesiredAccess) { - BOOL bManualReset; - bManualReset = (dwFlags & CREATE_WAITABLE_TIMER_MANUAL_RESET) ? TRUE : FALSE; + BOOL bManualReset = (dwFlags & CREATE_WAITABLE_TIMER_MANUAL_RESET) ? TRUE : FALSE; + + if (dwDesiredAccess != 0) + WLog_WARN(TAG, "%s [%s] does not support dwDesiredAccess 0x%08"PRIx32, __FUNCTION__, lpTimerName, + dwDesiredAccess); + return CreateWaitableTimerA(lpTimerAttributes, bManualReset, lpTimerName); } @@ -422,6 +432,12 @@ BOOL SetWaitableTimer(HANDLE hTimer, const LARGE_INTEGER* lpDueTime, LONG lPerio if (lPeriod < 0) return FALSE; + if (fResume) + { + WLog_ERR(TAG, "%s does not support fResume", __FUNCTION__); + return FALSE; + } + timer = (WINPR_TIMER*) Object; timer->lPeriod = lPeriod; /* milliseconds */ timer->pfnCompletionRoutine = pfnCompletionRoutine; @@ -547,11 +563,15 @@ BOOL SetWaitableTimerEx(HANDLE hTimer, const LARGE_INTEGER* lpDueTime, LONG lPer HANDLE OpenWaitableTimerA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpTimerName) { + /* TODO: Implement */ + WLog_ERR(TAG, "%s not implemented", __FUNCTION__); return NULL; } HANDLE OpenWaitableTimerW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpTimerName) { + /* TODO: Implement */ + WLog_ERR(TAG, "%s not implemented", __FUNCTION__); return NULL; } -- 2.7.4