summaryrefslogtreecommitdiffstats
path: root/Kod/display/ClientServerApp/Common/ReadABuffer.cpp
diff options
context:
space:
mode:
authorvikle012 <viktor.leek@liu.se>2019-09-11 13:57:14 +0200
committervikle012 <viktor.leek@liu.se>2019-09-11 13:57:14 +0200
commite66efbbe8df2dd4e7de0a1e9bd129cf92e00f92f (patch)
tree5ec35be0c219a2e6b017e12e450e76157b9de044 /Kod/display/ClientServerApp/Common/ReadABuffer.cpp
downloadtfyy51-e66efbbe8df2dd4e7de0a1e9bd129cf92e00f92f.tar.gz
Initializes repo.
Diffstat (limited to 'Kod/display/ClientServerApp/Common/ReadABuffer.cpp')
-rw-r--r--Kod/display/ClientServerApp/Common/ReadABuffer.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/Kod/display/ClientServerApp/Common/ReadABuffer.cpp b/Kod/display/ClientServerApp/Common/ReadABuffer.cpp
new file mode 100644
index 0000000..97bd9b5
--- /dev/null
+++ b/Kod/display/ClientServerApp/Common/ReadABuffer.cpp
@@ -0,0 +1,36 @@
+#include "ReadABuffer.h"
+
+BOOL ReadABuffer(unsigned char * lpBuf, DWORD dwToWrite, HANDLE hComm)
+{
+ OVERLAPPED osWrite = {0};
+ DWORD dwWritten;
+ BOOL fRes;
+
+ // Create this writes OVERLAPPED structure hEvent.
+ osWrite.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+ if (osWrite.hEvent == NULL)
+ // Error creating overlapped event handle.
+ return FALSE;
+
+ // Issue write.
+ if (!ReadFile(hComm, lpBuf, dwToWrite, &dwWritten, &osWrite)) {
+ if (GetLastError() != ERROR_IO_PENDING) {
+ // WriteFile failed, but it isn't delayed. Report error and abort.
+ fRes = FALSE;
+ }
+ else {
+ // Write is pending.
+ if (!GetOverlappedResult(hComm, &osWrite, &dwWritten, TRUE))
+ fRes = FALSE;
+ else
+ // Write operation completed successfully.
+ fRes = TRUE;
+ }
+ }
+ else
+ // WriteFile completed immediately.
+ fRes = TRUE;
+
+ CloseHandle(osWrite.hEvent);
+ return fRes;
+} \ No newline at end of file