changeset 93:d61f9ce3dacd

8071993: UART timeout feature is disabled by default Summary: DIO1.0.1: UART timeout feature is disabled by default. The second fex. First was wrong because I assumed inputTimeout == 0 means feature disabled, but spec says Integer.MAX_VALUE marker for feature disabled. Reviewed-by: snazarki Contributed-by: alexey.karaksin@oracle.com
author amironov
date Fri, 30 Jan 2015 12:21:52 +0300
parents 9753293dba56
children 6650624647cf
files src/share/classes/com/oracle/dio/uart/impl/UARTImpl.java
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/oracle/dio/uart/impl/UARTImpl.java	Thu Jan 29 17:32:48 2015 +0300
+++ b/src/share/classes/com/oracle/dio/uart/impl/UARTImpl.java	Fri Jan 30 12:21:52 2015 +0300
@@ -85,7 +85,7 @@
     private Hashtable<Integer, UARTEventListener> eventListeners;
 
     private int receiveTriggerLevel;
-    private int inputTimeout;//init value 0 means timeout is desabled
+    private int inputTimeout = Integer.MAX_VALUE;//timeout is disabled
     private Timer receiveTimer;
 
 
@@ -456,7 +456,7 @@
         }else{
              eventListeners.put(eventId, listener);
              subscribe(eventId);
-             if(eventId == UARTEvent.INPUT_DATA_AVAILABLE){
+             if(eventId == UARTEvent.INPUT_DATA_AVAILABLE && inputTimeout < Integer.MAX_VALUE){
                 startReceiveTimer();
              }
         }
@@ -676,7 +676,7 @@
                 int readRes = read0(dst);
                 shiftBufferPosition(dst, ret + readRes);
                 if (dst.hasRemaining()) {
-                    if (!UARTEventHandler.getInstance().isDispatchThread() && inputTimeout > 0) {
+                    if (!UARTEventHandler.getInstance().isDispatchThread()) {
                         /*
                          * the user calls read() from the event callback, or inputTimeout is 0
                          * exit immediatelly,
@@ -685,7 +685,12 @@
                         startReading(dst, getLocalInputRoundListener());
                         synchronized(synchReadLock){
                             try{
-                                synchReadLock.wait(inputTimeout);
+                                if(inputTimeout == Integer.MAX_VALUE){
+                                    //timeout disabled, wait forever or till the buffer is fullfilled
+                                    synchReadLock.wait();
+                                }else{
+                                    synchReadLock.wait(inputTimeout);
+                                }
                             }catch(InterruptedException iE){
                                 throw new IOException();
                             }