summaryrefslogtreecommitdiffstats
path: root/winpr/libwinpr/comm/test/TestCommMonitor.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:24:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:24:41 +0000
commita9bcc81f821d7c66f623779fa5147e728eb3c388 (patch)
tree98676963bcdd537ae5908a067a8eb110b93486a6 /winpr/libwinpr/comm/test/TestCommMonitor.c
parentInitial commit. (diff)
downloadfreerdp3-a9bcc81f821d7c66f623779fa5147e728eb3c388.tar.xz
freerdp3-a9bcc81f821d7c66f623779fa5147e728eb3c388.zip
Adding upstream version 3.3.0+dfsg1.upstream/3.3.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'winpr/libwinpr/comm/test/TestCommMonitor.c')
-rw-r--r--winpr/libwinpr/comm/test/TestCommMonitor.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/winpr/libwinpr/comm/test/TestCommMonitor.c b/winpr/libwinpr/comm/test/TestCommMonitor.c
new file mode 100644
index 0000000..fe28a86
--- /dev/null
+++ b/winpr/libwinpr/comm/test/TestCommMonitor.c
@@ -0,0 +1,70 @@
+
+#include <winpr/crt.h>
+#include <winpr/comm.h>
+#include <winpr/file.h>
+#include <winpr/synch.h>
+#include <winpr/handle.h>
+
+int TestCommMonitor(int argc, char* argv[])
+{
+ HANDLE hComm;
+ DWORD dwError;
+ BOOL fSuccess;
+ DWORD dwEvtMask;
+ OVERLAPPED overlapped = { 0 };
+ LPCSTR lpFileName = "\\\\.\\COM1";
+
+ hComm = CreateFileA(lpFileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
+ FILE_FLAG_OVERLAPPED, NULL);
+
+ if (!hComm || (hComm == INVALID_HANDLE_VALUE))
+ {
+ printf("CreateFileA failure: %s\n", lpFileName);
+ return -1;
+ }
+
+ fSuccess = SetCommMask(hComm, EV_CTS | EV_DSR);
+
+ if (!fSuccess)
+ {
+ printf("SetCommMask failure: GetLastError() = %" PRIu32 "\n", GetLastError());
+ return -1;
+ }
+
+ if (!(overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
+ {
+ printf("CreateEvent failed: GetLastError() = %" PRIu32 "\n", GetLastError());
+ return -1;
+ }
+
+ if (WaitCommEvent(hComm, &dwEvtMask, &overlapped))
+ {
+ if (dwEvtMask & EV_DSR)
+ {
+ printf("EV_DSR\n");
+ }
+
+ if (dwEvtMask & EV_CTS)
+ {
+ printf("EV_CTS\n");
+ }
+ }
+ else
+ {
+ dwError = GetLastError();
+
+ if (dwError == ERROR_IO_PENDING)
+ {
+ printf("ERROR_IO_PENDING\n");
+ }
+ else
+ {
+ printf("WaitCommEvent failure: GetLastError() = %" PRIu32 "\n", dwError);
+ return -1;
+ }
+ }
+
+ CloseHandle(hComm);
+
+ return 0;
+}