[prev in list] [next in list] [prev in thread] [next in thread] 

List:       rxtx
Subject:    [Rxtx] Patch for WinCE readArray
From:       Ivan Maidanski <ivmai () mail ! ru>
Date:       2009-11-24 19:26:00
Message-ID: E1ND11U-00008t-00.ivmai-mail-ru () f136 ! mail ! ru
[Download RAW message or body]

Hi!

I've discovered a bug in readArray() of WinCE port - there ReadFile() is called in a \
loop (until, at least, threshold bytes are read) but the pointer in the buffer is not \
advanced (not a rare mistake). I also simplified the loop condition.

The patch is attached (assumes 2 my previous patches - 
http://mailman.qbang.org/pipermail/rxtx/2009-November/5247775.html and
http://mailman.qbang.org/pipermail/rxtx/2009-November/5247780.html).


["rxtx-devel-ivmai4.diff" (application/octet-stream)]

diff -ru CVS_plus_patches_1_3/rxtx-devel/WinCE/README updated/rxtx-devel/WinCE/README
--- CVS_plus_patches_1_3/rxtx-devel/WinCE/README	2009-11-23 11:58:18.000000000 +0300
+++ updated/rxtx-devel/WinCE/README	2009-11-23 17:21:43.728077400 +0300
@@ -39,7 +39,7 @@
 
 Tested with compilers:
 - MS VC++ v15.00 for ARM; and
-- CeGCC v0.9.1 arm-mingw32ce-gcc (GCC) 4.4.0.
+- CeGCC v0.59.1 arm-mingw32ce-gcc (GCC) 4.4.0.
 
 Tested on a WinCE 5.0 ARM PNA device.
 
diff -ru CVS_plus_patches_1_3/rxtx-devel/WinCE/gnu_io_RXTXPort.cpp \
                updated/rxtx-devel/WinCE/gnu_io_RXTXPort.cpp
--- CVS_plus_patches_1_3/rxtx-devel/WinCE/gnu_io_RXTXPort.cpp	2009-11-23 \
                11:24:26.000000000 +0300
+++ updated/rxtx-devel/WinCE/gnu_io_RXTXPort.cpp	2009-11-24 19:05:10.733746600 +0300
@@ -459,7 +459,7 @@
   |enabled |m bytes|enabled |x ms |    n bytes      | block for x ms or until \
                min(m,n) bytes are available
   --------------------------------------------------------------------------------------------------------
  
-  Enabling the Timeout OR Threshold with a value a zero is a special case.
+  Enabling the Timeout OR Threshold with a value of zero is a special case.
   This causes the underlying driver to poll for incoming data instead being event \
driven.  Otherwise, the behaviour is identical to having both the Timeout and \
                Threshold disabled.
   */
@@ -1040,13 +1040,17 @@
 
   jbyte *body = env->GetByteArrayElements(b, NULL);
   threshold = get_java_var_long(env, jobj, "threshold", "I");
-
+  
+  if (threshold > len)
+    threshold = len;
   do
   {
-    if (!ReadFile(hPort, (unsigned char *)(body+off), len, &dwNumBytesRead, NULL))
+    if (!ReadFile(hPort, body + off + dwTotalRead, len - dwTotalRead,
+        &dwNumBytesRead, NULL))
     { // ReadFile failed. Report error.
       CreateErrorMsg(GetLastError(), lpMsgBuf);
-      throw_java_exceptionW(env, IO_EXCEPTION, L"readArray - WriteFile", lpMsgBuf );
+      throw_java_exceptionW(env, IO_EXCEPTION, L"readArray - ReadFile",
+                            lpMsgBuf);
       // Free the buffers.
       ReleaseErrorMsg(lpMsgBuf);
       env->ReleaseByteArrayElements(b, body, JNI_ABORT);
@@ -1054,7 +1058,7 @@
     }
 
     dwTotalRead += dwNumBytesRead;
-  } while(dwNumBytesRead > 0 && threshold != 0 && dwTotalRead <= (DWORD)len && \
dwTotalRead < (DWORD)threshold); +  } while (dwNumBytesRead > 0 && (jint)dwTotalRead \
< threshold);  
   env->ReleaseByteArrayElements(b, body, 0);
   return dwTotalRead;



_______________________________________________
Rxtx mailing list
Rxtx@qbang.org
http://mailman.qbang.org/mailman/listinfo/rxtx


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic