[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Patch: Fix Win32 CreateEvent returns NULL on failure, not INVALID_HANDLE
From: |
Conrad T. Pino |
Subject: |
Patch: Fix Win32 CreateEvent returns NULL on failure, not INVALID_HANDLE_VALUE |
Date: |
Sat, 10 Sep 2005 22:03:40 -0700 |
This patch depends upon patches committed on "dev-bcb6-arm" branch
between revision tags "dev-bcb6-arm-0052" and "dev-bcb6-arm-0054".
This patch modifies the following files:
ChangeLog
src/serial.cpp
This patch is committed on "dev-bcb6-arm" branch between revision
tags "dev-bcb6-arm-0054" and "dev-bcb6-arm-0055".
Index: ChangeLog
===================================================================
RCS file: /cvsroot/gnutelephony/testing/commoncpp2/ChangeLog,v
retrieving revision 1.18.2.4
retrieving revision 1.18.2.5
diff -u -p -r1.18.2.4 -r1.18.2.5
--- ChangeLog 11 Sep 2005 04:19:18 -0000 1.18.2.4
+++ ChangeLog 11 Sep 2005 04:45:01 -0000 1.18.2.5
@@ -1,4 +1,5 @@
From Common C++ 1.3.18 to 1.3.19
+- fix Win32 CreateEvent returns NULL on failure, not INVALID_HANDLE_VALUE
- fix indentation error in WIN32 aRead method
- fix WIN32 aRead buffer overflow when Length < available data
- optimize WIN32 aRead and aWrite method zero length request cases
Index: src/serial.cpp
===================================================================
RCS file: /cvsroot/gnutelephony/testing/commoncpp2/src/serial.cpp,v
retrieving revision 1.1.1.1.2.4
retrieving revision 1.1.1.1.2.5
diff -u -p -r1.1.1.1.2.4 -r1.1.1.1.2.5
--- src/serial.cpp 11 Sep 2005 04:04:56 -0000 1.1.1.1.2.4
+++ src/serial.cpp 11 Sep 2005 04:45:01 -0000 1.1.1.1.2.5
@@ -473,6 +473,24 @@ void Serial::open(const char * fname)
}
#ifdef WIN32
+static bool overlapped_init(LPOVERLAPPED overlapped)
+{
+ memset(overlapped, 0, sizeof *overlapped);
+ overlapped->hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+
+ return overlapped->hEvent != NULL;
+}
+
+static void overlapped_fini(LPOVERLAPPED overlapped)
+{
+ if(overlapped->hEvent != NULL)
+ {
+ CloseHandle(overlapped->hEvent);
+
+ overlapped->hEvent = NULL;
+ }
+}
+
int Serial::aRead(char * Data, const int Length)
{
DWORD dwActualLength = 0, dwError = 0, dwReadLength = Length;
@@ -490,11 +508,8 @@ int Serial::aRead(char * Data, const int
if(dwReadLength > cs.cbInQue)
dwReadLength = cs.cbInQue;
- if(dwReadLength > 0)
+ if(dwReadLength > 0 && overlapped_init(&ol))
{
- memset(&ol, 0, sizeof(OVERLAPPED));
- ol.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
-
if(ReadFile(dev, Data, dwReadLength, &dwActualLength, &ol) ==
FALSE)
{
if(GetLastError() == ERROR_IO_PENDING)
@@ -506,8 +521,7 @@ int Serial::aRead(char * Data, const int
ClearCommError(dev, &dwError, &cs);
}
- if(ol.hEvent != INVALID_HANDLE_VALUE)
- CloseHandle(ol.hEvent);
+ overlapped_fini(&ol);
}
return dwActualLength;
@@ -522,11 +536,8 @@ int Serial::aWrite(const char * Data, co
// Clear the com port of any error condition prior to write
ClearCommError(dev, &dwError, &cs);
- if(dwWriteLength > 0)
+ if(dwWriteLength > 0 && overlapped_init(&ol))
{
- memset(&ol, 0, sizeof(OVERLAPPED));
- ol.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
-
if(WriteFile(dev, Data, dwWriteLength, &dwActualLength, &ol) ==
FALSE)
{
if(GetLastError() == ERROR_IO_PENDING)
@@ -538,8 +549,7 @@ int Serial::aWrite(const char * Data, co
ClearCommError(dev, &dwError, &cs);
}
- if(ol.hEvent != INVALID_HANDLE_VALUE)
- CloseHandle(ol.hEvent);
+ overlapped_fini(&ol);
}
return dwActualLength;
@@ -954,8 +964,7 @@ bool Serial::isPending(Pending pending,
DWORD dwMask;
BOOL suc;
- memset(&ol, 0, sizeof(OVERLAPPED));
- ol.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+ overlapped_init(&ol);
if(pending == pendingInput)
dwMask = EV_RXCHAR;
@@ -978,8 +987,7 @@ bool Serial::isPending(Pending pending,
ClearCommError(dev, &dwError, &cs);
}
- if(ol.hEvent != INVALID_HANDLE_VALUE)
- CloseHandle(ol.hEvent);
+ overlapped_fini(&ol);
Thread::exitCancel(save);
if(suc == FALSE)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Patch: Fix Win32 CreateEvent returns NULL on failure, not INVALID_HANDLE_VALUE,
Conrad T. Pino <=